Re: Re: Still don't know how to build this string ? how to concat ??

From: Andy Corteen <lbc(at)telecam(dot)demon(dot)co(dot)uk>
To: juerg(dot)rietmann(at)pup(dot)ch
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Re: Still don't know how to build this string ? how to concat ??
Date: 2001-03-27 14:22:37
Message-ID: 14918780083.20010327152237@telecam.demon.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Tuesday, March 27, 2001, 10:20:18 AM, you wrote:

jrpc> <snip...>

jrpc> Result:
jrpc> 01 1440
jrpc> 02 1460
jrpc> 03 1398

jrpc> The values (1440, ...) are the last entries of z_u_umfang for each z_u_typ.
jrpc> This is correct since in the function the list:= ... is overwritten until
jrpc> the last record is read.
jrpc> When I try to concat the list in the manner of list := list ||
jrpc> text(rec.z_u_umfang); the zustring is empty !

jrpc> Thanks for any help ... jr

jrpc> Query :
jrpc> select distinct z_u_typ, buildString(z_u_typ) as zustring from
jrpc> zylinder_umfang

jrpc> Function:
jrpc> CREATE FUNCTION buildString(bpchar) RETURNS text AS '
jrpc> DECLARE
jrpc> list text;
jrpc> rec record;
jrpc> BEGIN
jrpc> FOR rec IN SELECT z_u_umfang FROM zylinder_umfang WHERE z_u_typ
jrpc> = $1;
jrpc> list := text(rec.z_u_umfang);
jrpc> END LOOP;
jrpc> RETURN list;
jrpc> END;
jrpc> ' LANGUAGE 'plpgsql';

You seem to be constantly re-assigning "list", rather than adding to
it with each iteration of the "for loop".

Would:
...
list := list || ',' || text(rec.z_u_umfang)
...
be what your solution is missing?

--
Best regards,
Andy mailto:lbc(at)telecam(dot)demon(dot)co(dot)uk

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2001-03-27 15:24:16 Re: Upgrading from 6.2 to 7
Previous Message Sean Weissensee 2001-03-27 13:10:42 Upgrading from 6.2 to 7