Odd behavior of SELECT INTO in PL/pgSQL

From: <depstein(at)alliedtesting(dot)com>
To: <pgsql-bugs(at)postgresql(dot)org>
Cc: <pgagarinov(at)alliedtesting(dot)com>
Subject: Odd behavior of SELECT INTO in PL/pgSQL
Date: 2010-07-20 12:43:21
Message-ID: 29F36C7C98AB09499B1A209D48EAA615B49FD184A1@mail2a.alliedtesting.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PostgreSQL 8.4

Here is a PL/pgSQL procedure:

CREATE OR REPLACE FUNCTION select_test()
RETURNS void AS
$BODY$
DECLARE
id integer = -1;
BEGIN
select max(id) into id from test_table;
END
$BODY$
LANGUAGE 'plpgsql' VOLATILE
COST 100;

test_table is some table with an integer column 'id'.

The above procedure has an obvious mistake: the variable 'id' has the same name as a column in test_table. The select statement should have generated an error, preferably at function creation time.

What actually happens is that no error is thrown, the select result is not assigned to the variable 'id', and the function always returns -1.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Pavel Stehule 2010-07-20 13:08:08 Re: Odd behavior of SELECT INTO in PL/pgSQL
Previous Message Andres Freund 2010-07-19 20:35:42 Re: BUG #5566: High levels of savepoint nesting trigger stack overflow in AssignTransactionId