Re: pl/pgSQL variable substitution

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeremy Palmer <JPalmer(at)linz(dot)govt(dot)nz>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: pl/pgSQL variable substitution
Date: 2011-02-17 14:52:35
Message-ID: 6478.1297954355@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeremy Palmer <JPalmer(at)linz(dot)govt(dot)nz> writes:
> When I have a query that uses DESC reserved word within the function the following variable substitution occurs:

> ERROR: syntax error at or near "$1"
> LINE 1: SELECT foo.bar, foo."desc" FROM foo."desc" ORDER BY foo."desc" $1
> ^

The other two responses seem to have missed the point, which is that
plpgsql is substituting for something that couldn't possibly be a
variable name. That is fixed as of 9.0. I'm not sure whether it
solves your issue completely, though. In general, using identifiers
that look like reserved words is painful --- and don't forget that
in plpgsql, you have *two* sets of reserved words to worry about,
the core SQL language's plus plpgsql's own.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2011-02-17 15:26:22 Re: The efficiency of the WAL log writer
Previous Message Steven Elliott 2011-02-17 14:10:58 The efficiency of the WAL log writer