Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id E61A6476000 for ; Thu, 6 Jun 2002 11:38:58 -0400 (EDT) Received: from smtp0.telegraaf.net (smtp0.telegraaf.net [217.196.45.130]) by postgresql.org (Postfix) with ESMTP id 20359475F72 for ; Thu, 6 Jun 2002 11:38:57 -0400 (EDT) Received: from server9.telegraafnet.nl (server9.telegraafnet.nl [192.168.1.9]) by smtp0.telegraaf.net (Postfix) with ESMTP id 89C6C439E0 for ; Thu, 6 Jun 2002 17:38:51 +0200 (CEST) Received: from c22601 (c22601.ws.tem.nl [192.168.1.61]) by server9.telegraafnet.nl (8.11.1/8.11.1/Debian 8.11.0-6) with ESMTP id g56Fcp117562 for ; Thu, 6 Jun 2002 17:38:51 +0200 X-Authentication-Warning: server9.telegraafnet.nl: Host c22601.ws.tem.nl [192.168.1.61] claimed to be c22601 Content-Type: text/plain; charset="us-ascii" From: Ferdinand Smit To: pgsql-admin@postgresql.org Subject: About a PL/pgSQL function Date: Thu, 6 Jun 2002 17:38:51 +0200 User-Agent: KMail/1.4.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200206061738.51230.ferdinand@telegraafnet.nl> X-Archive-Number: 200206/31 X-Sequence-Number: 4466 Hi, I've created a little function, that returns an id and creates one if it does not exist. DROP FUNCTION fn(text,text); CREATE OR REPLACE FUNCTION fn(text,text) RETURNS INT AS ' DECLARE record_id INTEGER; BEGIN SELECT "id" INTO record_id FROM $1 WHERE def = $2 ; IF NOT FOUND THEN INSERT INTO $1 (def) VALUES($2); SELECT "id" INTO record_id FROM $1 WHERE def = $2; END IF; RETURN record_id; END; ' LANGUAGE 'plpgsql'; When i run it i get: NOTICE: Error occurred while executing PL/pgSQL function fn NOTICE: line 5 at select into variables ERROR: parser: parse error at or near "$1" When i create a function with a "static" table name, it works fine. EXECUTE does not allow SELECT INTO, so does anyone have an other solution? Ferdinand