Skip site navigation (1) Skip section navigation (2)

Re: Dynamic column names in plpgsql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Derrick Betts" <derrick(at)grifflink(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Dynamic column names in plpgsql
Date: 2006-01-31 14:34:24
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
"Derrick Betts" <derrick(at)grifflink(dot)com> writes:
> I'm trying to write a function that uses dynamic column names to fetch
> the results within those columns.

The only way to do that in plpgsql is to construct a query string and
execute it with EXECUTE (or FOR ... IN EXECUTE).  Anything else falls
foul of plpgsql's desire to cache execution plans for its queries.

The other PL languages make this easier, mainly because (a) their semantics
for database queries are always like EXECUTE, and (b) they all have more
extensive string-pushing facilities than plpgsql.  So you should consider
plperl, pltcl, and/or plpython depending on which languages you know.

			regards, tom lane

In response to

pgsql-novice by date

Next:From: Tom LaneDate: 2006-01-31 15:00:26
Subject: Re: copy
Previous:From: AndreasDate: 2006-01-31 14:32:46
Subject: Re: Upgrade to PG 8 before starting major development?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group