pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Richard Hayward <richard@tortoise.demon.co.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: function parameters : bug?
Date: Thu, 14 Jul 2005 09:14:15 +0100
Message-ID: <42D61ED7.1040707@archonet.com> (raw)
In-Reply-To: <ugu1d19614tuteki2jgm0496d58kcggdhn@4ax.com>
References: <ugu1d19614tuteki2jgm0496d58kcggdhn@4ax.com>

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



view thread (2+ messages)

Message-ID: <42D61ED7.1040707@archonet.com>
Permalink:  ../42D61ED7.1040707@archonet.com/
Also on:    postgresql.org/message-id/42D61ED7.1040707@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: dev@archonet.com, richard@tortoise.demon.co.uk
  Subject: Re: function parameters : bug?
  In-Reply-To: <42D61ED7.1040707@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox