Re: BUG #5352: Bug in PL/PgSQL "SELECT .. INTO" statement parser

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Oleg" <serovov(at)gmail(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #5352: Bug in PL/PgSQL "SELECT .. INTO" statement parser
Date: 2010-03-01 15:49:07
Message-ID: 17302.1267458547@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"Oleg" <serovov(at)gmail(dot)com> writes:
> DECLARE
> row_test1 test1%rowtype;
> row_test2 test2%rowtype;
> BEGIN
> SELECT test1, chunk_id
> FROM test1 JOIN test2 ON(chunk.id = test2.chunk_id)
> LIMIT 1
> INTO row_test1, row_test2;

> Will throw error:
> ERROR: LIMIT #,# syntax is not supported

The reason you're getting the weird error is that INTO is defined
to take either a list of scalar variables or a single rowtype variable.
Since row_test1 is a rowtype, the INTO is just "INTO row_test1" and
what's left in the actual SELECT statement is "LIMIT 1, row_test2".

I'm not sure whether we can do anything to make the error message
saner. It would be possible to throw error if the next token is a
comma after we've swallowed an "INTO rowtype_variable" clause, but
I'm afraid that that would break functions that work fine today.
So that cure might be worse than the disease. I seem to recall
having seen similar confusion before, though, so maybe we should
do it. I guess one argument for doing that is that we might someday
change plpgsql to allow multiple rowtype targets, in which case the
interpretation would change anyway...

In any case, the function is wrong as it stands.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Vitali 2010-03-01 15:52:42 BUG #5354: Type timestamptz doesn't allow to store time zone
Previous Message Alex Hunsaker 2010-03-01 15:24:28 Re: BUG #5352: Bug in PL/PgSQL "SELECT .. INTO" statement parser