X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 25AB8D1C939 for ; Sun, 10 Aug 2003 00:13:13 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 18368-09 for ; Sat, 9 Aug 2003 21:11:45 -0300 (ADT) Received: from mail.nucleus.com (mail1.nucleus.com [207.34.101.2]) by svr1.postgresql.org (Postfix) with ESMTP id 774F3D1C4BA for ; Sat, 9 Aug 2003 21:08:38 -0300 (ADT) Received: from 192.168.0.69 (unverified [68.145.160.252]) by mail.nucleus.com (Vircom SMTPRS 2.1.258) with ESMTP id ; Sat, 9 Aug 2003 18:08:25 -0600 From: "Andrew J. Kopciuch" Reply-To: akopciuch@olympusproject.org Organization: Olympus Open Source Project To: "Bernd Hoffmann" , Subject: Re: functions with plpgsql Date: Sat, 9 Aug 2003 18:04:10 -0600 User-Agent: KMail/1.5 References: <01b101c35eb3$6e75b2b0$3214a8c0@server> In-Reply-To: <01b101c35eb3$6e75b2b0$3214a8c0@server> X-MailKey: Flyers winning makes BDDF happy MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200308091804.10545.akopciuch@olympusproject.org> X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.2 tagged_above=0.0 required=5.0 tests=IN_REP_TO, QUOTED_EMAIL_TEXT, REFERENCES, REPLY_WITH_QUOTES, UPPERCASE_25_50, USER_AGENT X-Spam-Level: X-Archive-Number: 200308/33 X-Sequence-Number: 2210 > CREATE FUNCTION "next_id"(character varying) RETURNS integer AS ' > DECLARE > tabelle ALIAS FOR $1; > BEGIN > SELECT MAX(id)+1 FROM tabelle; > END; > ' LANGUAGE 'plpgsql' > > query: > > SELECT next_id(logs); > > error: > > PostgreSQL meldet: ERROR: parser: parse error at or near "$1" > > Can anybody help me? I do not think you can evaluate a declared vairable as a table name in the SELECT statement. I don't think you really need to do this though. If you have the table name already. why go: SELECT next_id(logs); And write this functios instead of: SELECT MAX(id) + 1 FROM logs; ?? Andy