From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Phil Steinke <lintec(at)engsoc(dot)queensu(dot)ca> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: plpgsql variable trouble |
Date: | 2000-11-30 15:32:10 |
Message-ID: | 4824.975598330@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Phil Steinke <lintec(at)engsoc(dot)queensu(dot)ca> writes:
> The problem with my code seems to be that the "given_field" variable isn't
> being interpolated in the assignment statement.
plpgsql is not a string-substitution language; you cannot expect the
value of a variable to be used as a table or field name in a query.
This is true because plpgsql precompiles queries into query plans
and saves the plans for repeated execution. That's a win for speed
but costs flexibility.
You *can* get that sort of result in pltcl or plperl, which don't do
any fancy caching. You just form the query as a string value using the
usual expression evaluation rules of those languages, and that string
gets submitted to the SQL parser and query engine. Less speed, more
flexibility.
I believe 7.1's plpgsql will have an EXECUTE <string> command that lets
you get the second effect in plpgsql too.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Doug Semig | 2000-11-30 15:37:37 | Re: Database cluster? |
Previous Message | Tom Lane | 2000-11-30 15:18:46 | Re: backup and store oids |