[vox-tech] pl/pgsql question: dynamic access to record.column

Jeff Newmiller jdnewmil at dcn.davis.ca.us
Wed Jan 10 19:01:07 PST 2007


Dylan Beaudette wrote:
> Hi,
> 
> I am learning how to use PL/PGSQL and have come upon something that I just 
> don't seem to be able to solve on my own. 
> 
> I have a function, which takes a column name as an argument. A FOR loop 
> iterates over rows, using a RECORD datatype to store each iteration of the 
> loop. 
> 
> If I hard-code in a column name into some calculation, things work fine. 
> However, I cannot seem to figure out how to _dynamically_ access a column 
> from a RECORD datatype:

My recommendation is... DON'T. SQL is very inefficient that way.

Instead of setting up your tables with a bunch of columns you need to
iterate over, set up one additional column that contains the "index" for
whatever you were iterating over by columns. and have a "values" column
to hold the data.

-- 
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------


More information about the vox-tech mailing list