Received: from localhost.localdomain (postgresql.org [64.49.215.8]) by localhost (Postfix) with ESMTP id 4C7AB475A93 for ; Thu, 23 May 2002 20:38:08 -0400 (EDT) Received: from tsmtp10.mail.isp (mailhost2.teleline.es [195.235.113.141]) by postgresql.org (Postfix) with ESMTP id 5CE09475998 for ; Thu, 23 May 2002 20:38:06 -0400 (EDT) Received: from terra.es ([212.166.175.4]) by tsmtp10.mail.isp (Netscape Messaging Server 4.15 tsmtp10 Mar 14 2002 21:29:48) with ESMTP id GWLB1901.JJ0; Fri, 24 May 2002 02:36:45 +0200 Message-ID: <3CED7D29.7E55D278@terra.es> Date: Fri, 24 May 2002 01:37:13 +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: Jeff Eckermann Cc: Lista SQL de postgres Subject: Re: Functions with dynamic queries References: <20020523224320.56005.qmail@web20809.mail.yahoo.com> Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Archive-Number: 200205/262 X-Sequence-Number: 7897 Jeff Eckermann escribi=F3: >=20 > Reminder to self: cast to text _before_ > concatenating(!) > I won't retype the code, but I hope you get the > idea... Yes, I have tried this: Create Function calc_stocks(text) Returns text AS ' Declare codart ALIAS For $1; all_stocks record; stock text; Begin Select sum(stocks.stkreal) as stock1, sum(stocks.stkpteser) as stock2 into all_stocks From stocks, prendas Where prendas.codprenda =3D stocks.codprenda and prendas.codarticulo =3D codart; stock :=3D (all_stocks.stock1::text || all_stocks.stock2::text); Return stock; End; ' language 'plpgsql';=20 But now I have got neither error nor=20 result. gesyweb=3D# select calc_stocks('020220064'); calc_stocks ------------- =20 (1 row)=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20= =20 -- Gabriel D.