From: | Suresh Kumar R <suresh(dot)arsenal29(at)gmail(dot)com> |
---|---|
To: | Merlin Moncure <mmoncure(at)gmail(dot)com> |
Cc: | pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Couldn't cast to record[] |
Date: | 2022-03-05 07:33:10 |
Message-ID: | CAH+y2+bvJu+Ng2rWx_hsnEMZ0HEcPX+XgAhQVg4FwJTZUV=0bg@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi Merlin,
I needed this because, I use postgres backend along with golang using
pgx driver. When i query address i need to specify OID of
address[](composite type). In my case i couldnt find the oid of that type
since its dynamic. Needed generic type so needed to cast to record[] which
has constant oid.
With regards
Suresh kumar R
On Fri, 4 Mar, 2022, 11:28 pm Merlin Moncure, <mmoncure(at)gmail(dot)com> wrote:
> On Thu, Mar 3, 2022 at 4:01 AM Suresh Kumar R
> <suresh(dot)arsenal29(at)gmail(dot)com> wrote:
> >
> > Hi, I created an table with composite type array as datatype for one
> column.
> > When I query that table I need the pg_typeof(column) as record[] instead
> of
> > composite_type[].
> > I tried creating a separate function and returning record[], but below
> error
> > is thrown,
> >
> > ERROR: PL/pgSQL functions cannot return type record[]
> >
> > Below is sample for my requirement.
> >
> > pali=# create type address as (number bigint, city varchar);
> > CREATE TYPE
> > pali=# create table person(name varchar, addresses address[]);
> > CREATE TABLE
> > pali=# insert into person values ('Michael', array[(82, 'NYC'),(24,
> > 'Dunkirk')]::address[]);
> > INSERT 0 1
> > pali=# select pg_typeof(addresses::record[]) from person ;
> > pg_typeof
> > -----------
> > address[]
> >
> > Here I expect record[] instead of address[].
>
>
> Why do you think you need this? If you need variant record storage,
> you probably want to go to jsonb, then use jsonb_populate_recordset to
> convert back to specific type.
>
> merlin
>
From | Date | Subject | |
---|---|---|---|
Next Message | obi reddy | 2022-03-05 11:07:51 | REG:DR DRILL |
Previous Message | Tom Lane | 2022-03-05 02:48:33 | Re: Interesting fail when migrating Pg from Ubuntu Bionic to Focal |