Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TAUgg-0001Wm-GG for pgsql-sql@postgresql.org; Sat, 08 Sep 2012 23:43:42 +0000 Received: from smtp102.prem.mail.ac4.yahoo.com ([76.13.13.41]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TAUgc-0004AV-Oo for pgsql-sql@postgresql.org; Sat, 08 Sep 2012 23:43:41 +0000 Received: (qmail 81578 invoked from network); 8 Sep 2012 23:43:36 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=19Ilb/AG7h9T+NBo7Vt+xVgAUyAhkTK1pXjj2RMHHzNcWVcHc1Eu+6UIMMkgdep//qRiAQmxbSa7MsQurQJLNCClW1cR+3/bkXpjUURWQqTuKWGW2ALljJWe9Wm78dCOshizTRfOTbySonfgsXRRQhiYn2Jp/o71rkUUAkbU5Gs= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1347147816; bh=9HMhE9fjPwIYYyX3J3EF8iDteTw7aSMAiwS8Lw9eqrM=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=rfQQmjRTw0c8QR9HRDHhyXOk4oqhkjS/BGK4iGIRVRNJmGxNzYAxojwVMPZtLn2F32baL8y3lM2wdvZLvm/k1Xht/LpBs30w84P6/vHeClhXXQiupG5Jj6kLP0X2n0ISKR3BVMEjzQ0cRBI/9QcBZxUAH+NEXUVSvYse948ky9A= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: c8fzLxAVM1nrx3HFDUVe61ypQoK50hnVXyRLhP.hUcV9yrH x.BDL4KG_ldd4F9.OHMqIypjpMuNDt2bosbouGjebW83tzLONMlafeu6SAT. 5ppa_Tmtf6UAJmufGo0NHY5nykguw6qtDj8bCdJrTeItUr49wJ8Cqf.G8zTV VYVcxht_JtpSPrQFwHD.67ce3hLgdk4KcP0KreB27Cr1gJVfZ16npAWKKTHR Urv0RrJyBKfBtWAyRXjTlhg2bm3jFeecIjNBJme6IIEfyRkn0RnG4tEYUU6b .jJ.VhojEzVaExOlcx7Y.F1kw79z2RmsGnoLbD0tOiVTeOktHZBoWxZHUUeM PZNjqY_PomVcSyadAQa5Fw_3n8amK64SpynLBT6Ts4Li4PFPjQfStqeZPlP0 lLmaaUxebWWVw701P_VqvTXy4x8VyA9cHJU7n X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp102.prem.mail.ac4.yahoo.com with SMTP; 08 Sep 2012 23:43:36 +0000 UTC From: "David Johnston" To: "'James Sharrett'" , References: In-Reply-To: Subject: Re: returning values to variables from dynamic SQL Date: Sat, 8 Sep 2012 19:42:42 -0400 Message-ID: <00ea01cd8e1b$a4435630$ecca0290$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQG59Fc8OPqmBHkEEHYhDCjbEyxblZeoTegQ Content-Language: en-us X-Pg-Spam-Score: -0.6 (/) X-Archive-Number: 201209/14 X-Sequence-Number: 36816 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> From: pgsql-sql-owner@postgresql.org = [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of James Sharrett Sent: Saturday, September 08, 2012 6:24 PM To: pgsql-sql@postgresql.org Subject: [SQL] returning values to variables from dynamic SQL I have a PG function ( using plpgsql) that calls a number of sub = functions also in plpgsql. =A0I have two main problems that seem to be variations = on the same theme of running dynamic SQL from a variable with the EXECUTE = statement and returning the results back to a variable defined in the calling function. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> Please read: http://www.postgresql.org/docs/9.0/interactive/plpgsql-statements.html#PL= PGS QL-STATEMENTS-EXECUTING-DYN Basically when you use "EXECUTE" you do not embed the "INTO" as part of = the SQL query but rather INTO becomes a modifier of the EXECUTE itself: EXECUTE 'some query' INTO {variables} David J.