Re: Couldn't cast to record[] - Mailing list pgsql-general

From Merlin Moncure
Subject Re: Couldn't cast to record[]
Date
Msg-id CAHyXU0wxMeEMiASOrNjeDiTnqOGNBhf5PngS3ugW=pAPcg0D2w@mail.gmail.com
Whole thread Raw
In response to Couldn't cast to record[]  (Suresh Kumar R <suresh.arsenal29@gmail.com>)
Responses Re: Couldn't cast to record[]
List pgsql-general
On Thu, Mar 3, 2022 at 4:01 AM Suresh Kumar R
<suresh.arsenal29@gmail.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



pgsql-general by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: [EXT] Re: Looking for tips on improving full-text search quality in Postgres
Next
From: Tom Lane
Date:
Subject: Re: Interesting fail when migrating Pg from Ubuntu Bionic to Focal