BUG #3649: Confusing error message: ERROR: syntax error at or near "$1"

From: "Audrius Meskauskas" <audrius(dot)meskauskas(at)spectraseis(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: BUG #3649: Confusing error message: ERROR: syntax error at or near "$1"
Date: 2007-10-03 07:42:11
Message-ID: 200710030742.l937gBe4095383@wwwmaster.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


The following bug has been logged online:

Bug reference: 3649
Logged by: Audrius Meskauskas
Email address: audrius(dot)meskauskas(at)spectraseis(dot)com
PostgreSQL version: PostgreSQL 8.1.
Operating system: SUSE
Description: Confusing error message: ERROR: syntax error at or near
"$1"
Details:

When defining the PL/pgSQL function, the error message "ERROR: syntax error
at or near "$1" " appears in the case when the name of the local variable
clashes with the name of the database table. If find this message highly
unsupportative, as it does not provide any hint about the real reason of the
problem.

The test case:
-- Checks if the same sensor is not measuring at the same time
-- for another point.
create or replace function test()
returns void as '
declare
-- dttx integer; -- and this works
dtt integer; -- syntax error at or near "$1"
v varchar;

begin
select dtt.serial into v from dtt where id = 1;
end;
' LANGUAGE plpgsql;

In this example, the variable name dtt conflicts with the table name dtt.
The problem may look trivial here, but it is distillation from much larger
code where it was not easy to locate.

Expected behavior: message like "variabe name dtt conflicts with table name"
or at least "naming conflict" if it seems too problematic to implement.

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2007-10-03 12:52:23 Re: BUG #3648: Server crashes when trying to create a table
Previous Message Anton 2007-10-03 05:45:02 BUG #3648: Server crashes when trying to create a table