Re: Convert text to user defined datatype

From: aditya desai <admad123(at)gmail(dot)com>
To: "Voillequin, Jean-Marc" <Jean-Marc(dot)Voillequin(at)moodys(dot)com>
Cc: pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
Subject: Re: Convert text to user defined datatype
Date: 2021-10-23 14:31:52
Message-ID: CAN0SRDFGYOKxvpR5svU8s2rjmQ9+tr5+jGdnfSYvn6eMPJ1PFQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Thanks Jean. However I am trying this inside procedure and getting an
error. Will try to send screenshot.

On Saturday, October 23, 2021, Voillequin, Jean-Marc <
Jean-Marc(dot)Voillequin(at)moodys(dot)com> wrote:

> Maybe needless,
>
>
>
> xxx=> create type t2 as (t2 varchar(30)[]);
>
> CREATE TYPE
>
> xxx=> select ('("{a,b,c}")')::t2;
>
> t2
>
> -------------
>
> ("{a,b,c}")
>
> (1 row)
>
>
>
> *From:* aditya desai <admad123(at)gmail(dot)com>
> *Sent:* Saturday, October 23, 2021 11:40 AM
> *To:* pgsql-sql <pgsql-sql(at)lists(dot)postgresql(dot)org>
> *Subject:* Convert text to user defined datatype
>
>
>
>
>
> *CAUTION:* This email originated from outside of Moody's. Do not click
> links or open attachments unless you recognize the sender and know the
> content is safe.
>
>
>
> Hi,
>
> I have a user defined data type as below.
>
>
>
> postgres=# \d t2;
>
> Composite type "public.t2"
>
> Column | Type | Collation | Nullable | Default
>
> --------+-------------------------+-----------+----------+---------
>
> t2 | character varying(30)[] | | |
>
>
>
>
>
> I need to cast values to the above type. Getting error below.
>
>
>
> postgres=# CREATE CAST (text as t2) without function;
>
> ERROR: source and target data types are not physically compatible
>
>
>
> If I have to create a CAST with function. Could you please suggest how to
> write this function?
>
>
>
> Regards,
>
> Aditya.
>
>
>
>
>
>
>
>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2021-10-23 14:39:03 Re: Convert text to user defined datatype
Previous Message Voillequin, Jean-Marc 2021-10-23 14:18:42 RE: Convert text to user defined datatype