Re: Couldn't cast to record[]

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Suresh Kumar R <suresh(dot)arsenal29(at)gmail(dot)com>
Cc: Merlin Moncure <mmoncure(at)gmail(dot)com>, pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Couldn't cast to record[]
Date: 2022-03-05 15:29:29
Message-ID: 4071820.1646494169@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Suresh Kumar R <suresh(dot)arsenal29(at)gmail(dot)com> writes:
> 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.

The usual advice is to look it up on the fly. As an example:

regression=# create type address as (f1 text, f2 text);
CREATE TYPE
regression=# select 'address[]'::regtype;
regtype
-----------
address[]
(1 row)

regression=# select 'address[]'::regtype::oid;
oid
--------
127056
(1 row)

If the client-side stack wants a type OID for a result column,
it's unlikely to be satisfied with a pseudotype OID anyway.
That provides next-to-no useful information about how to
interpret values. Are you sure you can't just leave the type
unspecified (e.g. zero) in whatever API is giving you trouble?

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message hubert depesz lubaczewski 2022-03-06 14:04:02 Re: Interesting fail when migrating Pg from Ubuntu Bionic to Focal
Previous Message obi reddy 2022-03-05 11:07:51 REG:DR DRILL