Re: Dynamically discovering field names in PLPGSQL queries - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Dynamically discovering field names in PLPGSQL queries
Date
Msg-id 20010821072253.B4270@wolff.to
Whole thread Raw
In response to Dynamically discovering field names in PLPGSQL queries  ("Oberpriller, Wade D." <oberpwd@nsc-msg01.network.com>)
List pgsql-general
On Mon, Aug 20, 2001 at 04:44:13PM -0500,
  "Oberpriller, Wade D." <oberpwd@nsc-msg01.network.com> wrote:
> Is there a way to discover the names of the fields in a record from a SELECT
> statement in PLPGSQL?
>
> For example:
>
> SELECT INTO REC * FROM mytable;
>
> Is there a mechanism to determine what the "*" expanded to? or does a
> programmer always have to know the layout of the table apriori?

I think the following will work:
select attname from pg_attribute, pg_class where attrelid = relfilenode and
attnum > 0 and relname = 'mytable' order by attnum;

I tried this on one of my tables and it looked OK.

pgsql-general by date:

Previous
From: "Jim Buttafuoco"
Date:
Subject: Re: clustering and/or failover?
Next
From: newsreader@mediaone.net
Date:
Subject: Re: Re: is this possible? it should be!