agora inbox for pgsql-sql@postgresql.org
help / color / mirror / Atom feedConvert text to user defined datatype
5+ messages / 3 participants
[nested] [flat]
* Convert text to user defined datatype
@ 2021-10-23 09:40 aditya desai <admad123@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: aditya desai @ 2021-10-23 09:40 UTC (permalink / raw)
To: pgsql-sql <pgsql-sql@lists.postgresql.org>
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.
^ permalink raw reply [nested|flat] 5+ messages in thread
* RE: Convert text to user defined datatype
@ 2021-10-23 14:18 Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
parent: aditya desai <admad123@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Voillequin, Jean-Marc @ 2021-10-23 14:18 UTC (permalink / raw)
To: aditya desai <admad123@gmail.com>; pgsql-sql <pgsql-sql@lists.postgresql.org>
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@gmail.com>
Sent: Saturday, October 23, 2021 11:40 AM
To: pgsql-sql <pgsql-sql@lists.postgresql.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.
-----------------------------------------
Moody's monitors email communications through its networks for regulatory compliance purposes and to protect its customers, employees and business and where allowed to do so by applicable law. The information contained in this e-mail message, and any attachment thereto, is confidential and may not be disclosed without our express permission. If you are not the intended recipient or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that you have received this message in error and that any review, dissemination, distribution or copying of this message, or any attachment thereto, in whole or in part, is strictly prohibited. If you have received this message in error, please immediately notify us by telephone, fax or e-mail and delete the message and all of its attachments. Every effort is made to keep our network free from viruses. You should, however, review this e-mail message, as well as any attachment thereto, for viruses. We take no responsibility and have no liability for any computer virus which may be transferred via this e-mail message.
-----------------------------------------
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Convert text to user defined datatype
@ 2021-10-23 14:31 aditya desai <admad123@gmail.com>
parent: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
0 siblings, 1 reply; 5+ messages in thread
From: aditya desai @ 2021-10-23 14:31 UTC (permalink / raw)
To: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; +Cc: pgsql-sql <pgsql-sql@lists.postgresql.org>
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.Voillequin@moodys.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@gmail.com>
> *Sent:* Saturday, October 23, 2021 11:40 AM
> *To:* pgsql-sql <pgsql-sql@lists.postgresql.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.
>
>
>
>
>
>
>
>
>
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Convert text to user defined datatype
@ 2021-10-23 14:39 Tom Lane <tgl@sss.pgh.pa.us>
parent: aditya desai <admad123@gmail.com>
0 siblings, 1 reply; 5+ messages in thread
From: Tom Lane @ 2021-10-23 14:39 UTC (permalink / raw)
To: aditya desai <admad123@gmail.com>; +Cc: Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>; pgsql-sql <pgsql-sql@lists.postgresql.org>
aditya desai <admad123@gmail.com> writes:
> Thanks Jean. However I am trying this inside procedure and getting an
> error. Will try to send screenshot.
That's frowned on around here. Can't you copy-and-paste the code
and the error message?
As Jean-Marc says, you shouldn't really need a defined CAST
object to cast to or from text; Postgres will interpret that
as a request to apply the datatype's I/O functions.
You can formalize that by creating a cast "WITH INOUT", but
you shouldn't need to, so I think your problem here is something
different from what you said. Hard to give more advice without
seeing the problem code and the specific error.
regards, tom lane
^ permalink raw reply [nested|flat] 5+ messages in thread
* Re: Convert text to user defined datatype
@ 2021-10-25 03:27 aditya desai <admad123@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 5+ messages in thread
From: aditya desai @ 2021-10-25 03:27 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; pgsql-sql <pgsql-sql@lists.postgresql.org>
Thanks guys! Let me try out few things and get back to you in case I am
stuck.
On Sat, Oct 23, 2021 at 8:09 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:
> aditya desai <admad123@gmail.com> writes:
> > Thanks Jean. However I am trying this inside procedure and getting an
> > error. Will try to send screenshot.
>
> That's frowned on around here. Can't you copy-and-paste the code
> and the error message?
>
> As Jean-Marc says, you shouldn't really need a defined CAST
> object to cast to or from text; Postgres will interpret that
> as a request to apply the datatype's I/O functions.
>
> You can formalize that by creating a cast "WITH INOUT", but
> you shouldn't need to, so I think your problem here is something
> different from what you said. Hard to give more advice without
> seeing the problem code and the specific error.
>
> regards, tom lane
>
^ permalink raw reply [nested|flat] 5+ messages in thread
end of thread, other threads:[~2021-10-25 03:27 UTC | newest]
Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-10-23 09:40 Convert text to user defined datatype aditya desai <admad123@gmail.com>
2021-10-23 14:18 ` Voillequin, Jean-Marc <Jean-Marc.Voillequin@moodys.com>
2021-10-23 14:31 ` aditya desai <admad123@gmail.com>
2021-10-23 14:39 ` Tom Lane <tgl@sss.pgh.pa.us>
2021-10-25 03:27 ` aditya desai <admad123@gmail.com>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox