Received: from ns.krot.org (ns.krot.org [193.212.103.165]) by postgresql.org (8.11.3/8.11.4) with SMTP id f9UME7P59618 for ; Tue, 30 Oct 2001 17:14:08 -0500 (EST) (envelope-from postgresql@envisity.com) Received: (qmail 28606 invoked by uid 67); 30 Oct 2001 22:12:16 -0000 Message-ID: <20011030221216.23528.qmail@ns.krot.org> Content-Type: text/plain; charset=ISO-8859-1 Content-Disposition: inline MIME-Version: 1.0 From: "Aasmund Midttun Godal" To: tobbe@embryo.se Cc: pgsql-sql@postgresql.org Subject: Re: Strange loop Date: Tue, 30 Oct 2001 22:12:16 GMT X-Mailer: Googley-Moogley In-Reply-To: from TorbjöRn Andersson on Tue, 30 Oct 2001 22:05:15 +0100 References: Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by postgresql.org id f9UMLrM61467 X-Archive-Number: 200110/424 X-Sequence-Number: 5375 You are concatenating with a null value, which causes the result to be null. See below, I have fixed it. Regards, Aasmund On Tue, 30 Oct 2001 22:05:15 +0100, Torbjörn Andersson wrote: > Hi, > > I need some help with the function below. My intention is to hand the > content of result_store and sort it out so that I can have a complete > recordset. But for some reason result_store is returned empty. It works fine > for one row but the concatenation of result_store and result does not seem > to work. > > Can some one pleas explain why? > > > > CREATE FUNCTION f_snus() > RETURNS varchar > AS > ' DECLARE > result varchar := ''''; > result_store varchar := ''''; > row record; > BEGIN > FOR row IN > SELECT snus_id, namn, betyg FROM snus ORDER BY betyg > LOOP > SELECT INTO result row.snus_id || ''\t'' || row.namn || > ''\t'' || row.betyg || ''\n''; > result_store := result_store || result; > END LOOP; > RETURN result_store; > END; > ' LANGUAGE 'PLPGSQL'; > > > > Regards > > Torbjörn Andersson > --------------------------------------------------- > Embryo Communication phone: +46 (0) 31-774 39 11(00) > Kungsgatan 7a fax: +46 (0)31 774 07 80 > S-411 19 Göteborg mobile: 0708-30 70 04 > Sweden home: http://www.embryo.se/ > mail: torbjorn.andersson@embryo.se > --------------------------------------------------- > "Att idag tänka annorlunda än igår skiljer den vise från den envise." - John > Steinbeck > > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org Aasmund Midttun Godal aasmund@godal.com - http://www.godal.com/ +47 40 45 20 46