Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id F0DE9635B84 for ; Thu, 17 Sep 2009 12:44:48 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 41514-07 for ; Thu, 17 Sep 2009 15:44:37 +0000 (UTC) X-Greylist: delayed 00:08:13.948981 by SQLgrey-1.7.6 Received: from mail.geops.de (schwalbe2.geops.de [80.72.135.100]) by mail.postgresql.org (Postfix) with ESMTP id 7970F63460C for ; Thu, 17 Sep 2009 12:44:35 -0300 (ADT) Received: from [192.168.1.111] (pd95bc5db.dip0.t-ipconnect.de [217.91.197.219]) by mail.geops.de (Postfix) with ESMTPSA id C3851130318 for ; Thu, 17 Sep 2009 17:36:17 +0200 (CEST) Message-ID: <4AB25758.60702@geops.de> Date: Thu, 17 Sep 2009 17:35:52 +0200 From: Nico Mandery User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Rules, functions and RETURNING X-Enigmail-Version: 0.96.0 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.599 tagged_above=-10 required=5 tests=BAYES_00=-2.599 X-Spam-Level: X-Archive-Number: 200909/81 X-Sequence-Number: 33146 Hello list, I am trying to wirte a rule which calls a PLPgSQL-function upon an Insert in a table. Here is a somewhat simplified example of what i got so far: CREATE TABLE mytable ( mytable_id serial PRIMARY KEY, something text ); CREATE OR REPLACE FUNCTION _rule_insert_my(something text) RETURNS integer AS $BODY$ BEGIN -- do something return mytable_id; END; $BODY$ LANGUAGE 'plpgsql' VOLATILE COST 100; CREATE OR REPLACE RULE _insert AS ON INSERT TO mytable DO INSTEAD SELECT _rule_insert_my(new.something) AS mytable_id; So far this works quite well. But I got a few situations where I need to do a query which uses RETURNING to get the value of the newly generated primary key. Like this one: INSERT INTO mytable (something) VALUES ('some text') RETURNING mytable_id; This breaks because I did not specify a RETURNING-Clause in the rule. But how can specify RETURNING with SELECT? Thank your in advance for your help. regards, nico -- Nico Mandery