Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 33A5A47546E for ; Thu, 23 May 2002 17:49:20 -0400 (EDT) Received: from tsmtp7.mail.isp (mailhost2.teleline.es [195.235.113.141]) by postgresql.org (Postfix) with ESMTP id 7532F47545C for ; Thu, 23 May 2002 17:49:18 -0400 (EDT) Received: from terra.es ([212.166.173.195]) by tsmtp7.mail.isp (Netscape Messaging Server 4.15 tsmtp7 Mar 14 2002 21:29:48) with ESMTP id GWL37W01.B5Y; Thu, 23 May 2002 23:47:56 +0200 Message-ID: <3CED5594.85BF8596@terra.es> Date: Thu, 23 May 2002 22:48:20 +0200 From: Gabriel Dovalo Carril X-Mailer: Mozilla 4.76 [es] (X11; U; Linux 2.4.0-4GB i686) X-Accept-Language: en MIME-Version: 1.0 To: "Rajesh Kumar Mallah." Cc: Lista SQL de postgres Subject: Re: Functions with dynamic queries References: <3CECC5C5.BDF77592@terra.es> <200205231914.27923.mallah@trade-india.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200205/259 X-Sequence-Number: 7894 > you may not need a function at all if your case is that simple . you > can use subselects and || operators to do many complicated things.. > can we know a bit more abt. your specific problem Ok. I have this query: Select sum(stocks.stkreal)::text || ',' || sum(stocks.stkpteser)::text as stock From stocks, prendas Where prendas.codprenda = stocks.codprenda and prendas.codarticulo = '020720004'; And I want to create a function which receives "codarticulo" as a parameter. *---------------- Create Function calc_stocks(text) Returns text AS ' Declare codart ALIAS For $1; all_stocks record; Begin Execute '' Select sum(stocks.stkreal)::text || '' || '''''' ,'''''' || '' || '' || ''sum(stocks.stkpteser)::text as stock '' || ''into all_stocks '' || ''From stocks, prendas '' || ''Where prendas.codprenda = stocks.codprenda and '' || ''prendas.codarticulo = codart; '' Return all_stocks.stock; End; ' language 'plpgsql'; *----------------- gesyweb=# select calc_stocks('020220064'); ERROR: record all_stocks is unassigned yet gesyweb=#