pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Possible to access value in RECORD without knowing column name?
2+ messages / 2 participants
[nested] [flat]

* Possible to access value in RECORD without knowing column name?
@ 2007-05-02 19:17 Collin Peters <cadiolis@gmail.com>
  2007-05-02 19:26 ` Re: Possible to access value in RECORD without knowing column name? Richard Albright <ralbright@insiderscore.com>
  0 siblings, 1 reply; 2+ messages in thread

From: Collin Peters @ 2007-05-02 19:17 UTC (permalink / raw)
  To: pgsql-sql

In plpgsl, if I have a RECORD variable that is populated via some
dynamic SQL, is it possible to access the columns in that RECORD
object without knowing the column names?  I.e. Can I grab whatever
value is the 3rd column?

random_colname = 'foobar';
sql = 'SELECT col1, col2, ' || random_colname || ' FROM table';

FOR mviews IN EXECUTE sql LOOP
   --possible to access 3rd column of mviews?  something like mviews[3]?
END LOOP;

Regards,
Collin



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Possible to access value in RECORD without knowing column name?
  2007-05-02 19:17 Possible to access value in RECORD without knowing column name? Collin Peters <cadiolis@gmail.com>
@ 2007-05-02 19:26 ` Richard Albright <ralbright@insiderscore.com>
  0 siblings, 0 replies; 2+ messages in thread

From: Richard Albright @ 2007-05-02 19:26 UTC (permalink / raw)
  To: Collin Peters <cadiolis@gmail.com>; +Cc: pgsql-sql

my_column = 'foo'
sql = 'select col1, col2, ' || my_column || ' as bar from mytable;
for myrecord in execute sql
loop
	myvariable = myrecord.bar
end loop;

On Wed, 2007-05-02 at 12:17 -0700, Collin Peters wrote:
> In plpgsl, if I have a RECORD variable that is populated via some
> dynamic SQL, is it possible to access the columns in that RECORD
> object without knowing the column names?  I.e. Can I grab whatever
> value is the 3rd column?
> 
> random_colname = 'foobar';
> sql = 'SELECT col1, col2, ' || random_colname || ' FROM table';
> 
> FOR mviews IN EXECUTE sql LOOP
>    --possible to access 3rd column of mviews?  something like mviews[3]?
> END LOOP;
> 
> Regards,
> Collin
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 1: if posting/reading through Usenet, please send an appropriate
>        subscribe-nomail command to majordomo@postgresql.org so that your
>        message can get through to the mailing list cleanly
-- 
Rick Albright
Senior Quantitative Analyst
Indie Research, LLC
254 Witherspoon Street
Princeton, NJ 08542
(609)497-1030
ralbright@insiderscore.com




^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2007-05-02 19:26 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2007-05-02 19:17 Possible to access value in RECORD without knowing column name? Collin Peters <cadiolis@gmail.com>
2007-05-02 19:26 ` Richard Albright <ralbright@insiderscore.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox