Re: (Pl/SQL) Obtaining field names from record 'variable'

From: Elvis Henríquez <henriquez(dot)elvis(at)gmail(dot)com>
To: "Allan Kamau" <kamauallan(at)yahoo(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org
Subject: Re: (Pl/SQL) Obtaining field names from record 'variable'
Date: 2007-12-12 02:34:52
Message-ID: 493343bd0712111834o14b436f5maacba22a76993776@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi. You could do a query to the system catalogs (pg_attribute, for example)
with your table name as the search criteria and the field names as the data;
loop through that data to create your query in a string variable, and then
EXECUTE it. While you are "looping" through the results of the system
catalog query, you can apply all the text functions available, so you can
split the field names, join them, etc.

I have done some similar queries. It's pretty simple.

Hope it helped.

Elvis.

On Dec 12, 2007 7:37 AM, Allan Kamau <kamauallan(at)yahoo(dot)com > wrote:

> Hi,
> I am writing a PL/SQL script to process data from a high dimensionality
> table where this table has most of it's field names encapsulating data. I
> would like to automatically loop through the fields of a RECORD variable
> (returned from a cursor) obtaining the field name and the field value.
> For example my table is listed below (briefly)
>
> create table my_table
> (
> id int not null-- default nextval(('my_table_seq'::text)::regclass)
> ,some_explanation varchar(20) not null
> ,D30 varchar(100) null
> ,W32 varchar(100) null
> ,C33 varchar(100) null
> ,V7 varchar(100) null
> ,...
> )
> ;
>
> The field name W32 consists of 'W' which is data I need and '32' which is
> data I also need along with the actual record value contained in this field.
>
>
>
> Allan.
>
>
>
>
>
> ____________________________________________________________________________________
> Be a better friend, newshound, and
> know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-admin by date

  From Date Subject
Next Message Peter Koczan 2007-12-12 03:01:18 Re: Legacy foreign keys
Previous Message kelvan 2007-12-12 01:17:57 pgagent on a mac