X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B1C1DD9C51 for ; Thu, 29 Sep 2005 15:18:19 -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 11950-08 for ; Thu, 29 Sep 2005 18:18:16 +0000 (GMT) Received: from ls405.htnet.hr (ls405.htnet.hr [195.29.150.97]) by svr1.postgresql.org (Postfix) with ESMTP id D2853D9AF7 for ; Thu, 29 Sep 2005 15:18:15 -0300 (ADT) Received: from ls401.t-com.hr (ls401.t-com.hr [195.29.150.236]) by ls405.htnet.hr (0.0.0/8.12.10) with ESMTP id j8TIIFWj012769 for ; Thu, 29 Sep 2005 20:18:15 +0200 Received: from ls401.t-com.hr (localhost.localdomain [127.0.0.1]) by ls401.t-com.hr (Qmlai) with ESMTP id 1791D70003 for ; Thu, 29 Sep 2005 20:18:15 +0200 (CEST) X-Envelope-Sender: mario.splivalo@mobart.hr Received: from 83-131-20-105.adsl.net.t-com.hr (83-131-20-105.adsl.net.t-com.hr [83.131.20.105]) by ls401.t-com.hr (Qmlai) with ESMTP id A696DA8029 for ; Thu, 29 Sep 2005 20:18:14 +0200 (CEST) Subject: EXECUTE with SELECT INTO variable, or alternatives From: Mario Splivalo Reply-To: mario.splivalo@mobart.hr To: pgsql-sql@postgresql.org Content-Type: text/plain Organization: Mob-Art Date: Thu, 29 Sep 2005 20:16:44 +0200 Message-Id: <1128017805.9061.5.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.2.1.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 required=5 tests=[none] X-Spam-Level: X-Archive-Number: 200509/296 X-Sequence-Number: 22843 I can assign a value to a variable in several ways: myVar := (SELECT col FROM table WHERE somecondition...) myVar := col FROM table WHERE somecondtition... SELECT col INTO myVar FROM table WHERE somecondition How do I do any of the above using EXECUTE? I need to be able to assign the value to a variable, a value returned by a querry on a temporary table. So far I have found workaround like this: myRec record; FOR rec IN EXECUTE ''SELECT col FROM table WHERE somecondition'' LOOP myVar := rec END LOOP Obviously, the above SELECT query returns only one row. Still, if is realy inconvinient to have FOR...LOOP...END LOOP construct for assigning the value to a variable 'read' from the temporary table. Mario