BUG #3649: Confusing error message: ERROR: syntax error at or near "$1" - Mailing list pgsql-bugs

From Audrius Meskauskas
Subject BUG #3649: Confusing error message: ERROR: syntax error at or near "$1"
Date
Msg-id 200710030742.l937gBe4095383@wwwmaster.postgresql.org
Whole thread Raw
List pgsql-bugs
The following bug has been logged online:

Bug reference:      3649
Logged by:          Audrius Meskauskas
Email address:      audrius.meskauskas@spectraseis.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.

pgsql-bugs by date:

Previous
From: "Anton"
Date:
Subject: BUG #3648: Server crashes when trying to create a table
Next
From: Alvaro Herrera
Date:
Subject: Re: BUG #3648: Server crashes when trying to create a table