Re: Anonymous record type and inner types.

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: Ronan Dunklau <rdunklau(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Anonymous record type and inner types.
Date: 2011-07-01 14:39:56
Message-ID: BANLkTinaT3sdcO_bKvq-DhsF3tr=K8HYEg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Jul 1, 2011 at 9:37 AM, Ronan Dunklau <rdunklau(at)gmail(dot)com> wrote:

> When I execute a statement such as "Select (an_int, a_varchar) as a_record
> from test, the type returned for a_record is "record" (oid 2249).
>
> Is the "inner type" information propagated somehow (that an_int is an integer,
> and a_varchar a varchar) ?
>
> If so, is it easily accessible in client libraries ? I'm using psycopg2 for
> python, which itself uses libpq.

I don't think the information about the components of the composite
type are automatically propagated to the client nor made accessible by
the libpq.

You may create an user-defined type representing the record you select
and cast the result to it: for example if you "create type thing as
(the_int integer, the_text varchar);" and then "select (an_int,
a_varchar)::thing from test", postgres will pass the "thing" oid to
the client, instead of the one of the generic "record". psycopg can be
programmed to return a tuple/namedtuple allowing you to get the
components as python values: see
<http://initd.org/psycopg/docs/extras.html#composite-types-casting>
for further details.

-- Daniele

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Guillaume Lelarge 2011-07-01 15:03:17 Re: pg_upgrade does not translate tablespace location to new cluster
Previous Message AI Rumman 2011-07-01 14:34:58 \i command in dblink