X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id E730752B79 for ; Sun, 10 Jul 2005 08:52:52 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 79763-02 for ; Sun, 10 Jul 2005 11:52:44 +0000 (GMT) Received: from floppy.pyrenet.fr (floppy.pyrenet.fr [194.116.145.2]) by svr1.postgresql.org (Postfix) with ESMTP id 799E852B6A for ; Sun, 10 Jul 2005 08:52:42 -0300 (ADT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id E68E730B41; Sun, 10 Jul 2005 13:57:07 +0200 (MET DST) From: Richard Hayward X-Newsgroups: pgsql.sql Subject: function parameters : bug? Date: Sun, 10 Jul 2005 11:52:10 +0100 Organization: Hub.Org Networking Services Lines: 52 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@news.hub.org X-Newsreader: Forte Agent 2.0/32.652 To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200507/116 X-Sequence-Number: 22094 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); return(0); end; $body$ LANGUAGE 'plpgsql'; select myfunction(123); 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. Problem vanishes with a different function parameter name: CREATE OR REPLACE FUNCTION myfunction (my_inta integer) RETURNS integer AS $body$ begin insert into myTable(inta) values (my_inta); return(0); end; $body$ LANGUAGE 'plpgsql' But, this means that if I change the design of my tables, I have to possibly change my function headers rather than merely the code inside them. regards Richard