Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y90e6-0006a2-Nz for pgsql-sql@arkaria.postgresql.org; Thu, 08 Jan 2015 00:08:14 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y90e5-00087w-Ij for pgsql-sql@arkaria.postgresql.org; Thu, 08 Jan 2015 00:08:13 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y90e4-00087q-MD for pgsql-sql@postgresql.org; Thu, 08 Jan 2015 00:08:12 +0000 Received: from mout.kundenserver.de ([212.227.126.130]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y90e1-0001I7-1b for pgsql-sql@postgresql.org; Thu, 08 Jan 2015 00:08:10 +0000 Received: from ayaki.localdomain ([106.68.221.229]) by mrelayeu.kundenserver.de (mreue002) with ESMTPSA (Nemesis) id 0LovMS-1XczoX3fGe-00euFN; Thu, 08 Jan 2015 01:08:06 +0100 Message-ID: <54ADCA60.1050904@2ndquadrant.com> Date: Thu, 08 Jan 2015 08:08:00 +0800 From: Craig Ringer Organization: 2nd Quadrant User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Roy Blum , pgsql-sql@postgresql.org Subject: Re: Use a TEXT string which is an output from a function for executing a new query in postgres References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:djYDYTPHHtAmdWEvvnpla1hHh51GocR0YyWIBDPn/5GA9JyCyc5 FhEyVUlT2q8L4yHIxC8NLWmxCw6NjrdNN4EYpTeGH2aPLE47MOp4T/7VOEccquNGAkenetb wWDfa14E7suOOdpdCBOSoTS8WS4lLSM6pHtTaElacCENb/gDC2dir+hrGDEvGYrhfuAsYmz R7Ep5qMTB6+4D8NISANkg== X-UI-Out-Filterresults: notjunk:1; X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 01/08/2015 02:12 AM, Roy Blum wrote: > I have created a function *myresult()* that receives as input Table > name, and a Prefix, it then creates an SQL one liner command to SELECT > from the specified table only the columns that share the designated > prefix. It output a string which is basically the desired SQL command. > My function is as follows and I show how I call it as well: This is reposted from Stack Overflow, where it has already been pretty comprehensively answered. http://stackoverflow.com/q/27808534/398670 http://stackoverflow.com/q/27824725/398670 As suggested earlier - return a refcursor. -- Craig Ringer http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql