Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 72420B37936 for ; Sun, 10 Jun 2012 13:58:49 -0300 (ADT) Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SdlTS-0006rk-2C for pgsql-bugs@postgresql.org; Sun, 10 Jun 2012 16:58:48 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SdlTE-0005rF-6S for pgsql-bugs@postgresql.org; Sun, 10 Jun 2012 16:58:32 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1SdlTD-0005ck-M6 for pgsql-bugs@postgresql.org; Sun, 10 Jun 2012 16:58:31 +0000 Date: Sun, 10 Jun 2012 16:58:31 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #6686: plpgsql Can't assign a variable with the output of a SQL Sentence which is not a SELECT To: pgsql-bugs@postgresql.org From: stormbyte@gmail.com X-Pg-Spam-Score: -1.0 (-) X-Archive-Number: 201206/94 X-Sequence-Number: 33321 The following bug has been logged on the website: Bug reference: 6686 Logged by: David Carlos Manuelda Email address: stormbyte@gmail.com PostgreSQL version: 9.1.4 Operating system: Gentoo Linux Description: = I will provide a really simple example: Suppose we have a table CREATE TABLE test(i INTEGER); Let's have a value: INSERT INTO test(i) VALUES (1); And a function CREATE OR REPLACE FUNCTION foo() RETURNS INTEGER AS $$ DECLARE dummy INTEGER; BEGIN dummy=3D(SELECT MAX(id) FROM test); -- VALID dummy=3D(UPDATE test SET i=3Di+10 RETURNING i); -- NOT VALID.. WHY? dummy=3D(INSERT INTO test(i) VALUES (10) RETURNING i); -- NOT VALID.. WHY? RETURN dummy; END; $$ Language 'plpgsql' VOLATILE; I get syntax error in both commented as not valid I think that since all queries actually returns a expected value, and since the function is not marked as stable, there is no reason for me to block that from happen.