Re: function parameters : bug?

From: Richard Huxton <dev(at)archonet(dot)com>
To: Richard Hayward <richard(at)tortoise(dot)demon(dot)co(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: function parameters : bug?
Date: 2005-07-14 08:14:15
Message-ID: 42D61ED7.1040707@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Richard Hayward wrote:
> pg 8.0.3
> This behaviour seems odd to me:
>
> CREATE TABLE mytable (
> inta INTEGER
> );
>
> CREATE OR REPLACE FUNCTION myfunction (inta integer) RETURNS integer
> AS
> $body$
> begin
> insert into mytable(inta) values (inta);

> ERROR: syntax error at or near "$1" at character 22
> QUERY: insert into myTable( $1 ) values ( $2 )
> CONTEXT: PL/pgSQL function "myfunction" line 2 at SQL statement
>
> The problem is with the line in my myfunction:
> insert into mytable(inta) values (inta);
>
> The server doesn't like the field name being the same as the name of
> the function parameter. I don't see why, as I can see no opportunity
> for ambiguity.

So what would this do?
SELECT inta+1 FROM mytable

Agreed, it's tricky, but without some variable marker (e.g. $my_param)
or removing inline SQL from the language, I'm not sure there's much to do.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2005-07-14 08:31:01 Re: Possible to use a table to tell what table to select from?
Previous Message Mark J Camilleri 2005-07-14 07:46:59 Error on dynamic code.