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

Re: dynamic field names in a function.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Soma Interesting <dfunct(at)telus(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: dynamic field names in a function.
Date: 2001-03-31 05:42:29
Message-ID: 22181.986017349@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-general
Soma Interesting <dfunct(at)telus(dot)net> writes:
> In the following, is there something I can do so that postgres will 
> evaluate NEW.qty to NEW.name, treating qty as a variable and evaluating it 
> before evaluating the field reference?

Plain PLSQL will not do this --- it wants to know field names when the
query is first compiled.  (This is a feature, not a bug, since it
implies that the query can be optimized during compilation.)

You could use PLTCL or PLPERL instead.  Both of them treat queries
as plain strings that you assemble out of whatever parts you please
and then pass to the query engine.  Of course you pay the cost of
re-planning the query from scratch every time --- there's no free lunch.

In 7.1, PLSQL can do that trick too, via its new EXECUTE statement.

			regards, tom lane

In response to

Responses

pgsql-general by date

Next:From: Tom LaneDate: 2001-03-31 05:54:42
Subject: Re: Stupid Access-Question
Previous:From: Tom LaneDate: 2001-03-31 04:56:26
Subject: Re: Consistent pg_dump's

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