pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Strange loop
3+ messages / 3 participants
[nested] [flat]

* Strange loop
@ 2001-10-30 21:05 Torbjörn Andersson <tobbe@embryo.se>
  2001-10-30 22:12 ` Re: Strange loop Aasmund Midttun Godal <postgresql@envisity.com>
  2001-10-30 22:20 ` Re: Strange loop Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 2 replies; 3+ messages in thread

From: Torbjörn Andersson @ 2001-10-30 21:05 UTC (permalink / raw)
  To: pgsql-sql

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




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Strange loop
  2001-10-30 21:05 Strange loop Torbjörn Andersson <tobbe@embryo.se>
@ 2001-10-30 22:12 ` Aasmund Midttun Godal <postgresql@envisity.com>
  1 sibling, 0 replies; 3+ messages in thread

From: Aasmund Midttun Godal @ 2001-10-30 22:12 UTC (permalink / raw)
  To: tobbe@embryo.se; +Cc: pgsql-sql

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 <tobbe@embryo.se> 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: Strange loop
  2001-10-30 21:05 Strange loop Torbjörn Andersson <tobbe@embryo.se>
@ 2001-10-30 22:20 ` Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 3+ messages in thread

From: Tom Lane @ 2001-10-30 22:20 UTC (permalink / raw)
  To: Torbjörn Andersson <tobbe@embryo.se>; +Cc: pgsql-sql

Torbj=?ISO-8859-1?B?9g==?=rn Andersson <tobbe@embryo.se> writes:
> 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.

Try initializing result_store to something other than NULL ...

			regards, tom lane



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2001-10-30 22:20 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-10-30 21:05 Strange loop Torbjörn Andersson <tobbe@embryo.se>
2001-10-30 22:12 ` Aasmund Midttun Godal <postgresql@envisity.com>
2001-10-30 22:20 ` Tom Lane <tgl@sss.pgh.pa.us>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox