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

From: Jeff Eckermann <jeckermann(at)verio(dot)net>
To: "'juerg(dot)rietmann(at)pup(dot)ch'" <juerg(dot)rietmann(at)pup(dot)ch>, pgsql-sql(at)postgresql(dot)org
Subject: RE: Still don't know how to build this string ?
Date: 2001-03-26 17:02:29
Message-ID: 08CD1781F85AD4118E0800A0C9B8580B0949D7@NEZU
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Still learning this stuff, so please be gentle...

jeff=# select * from test_it;
typ | diam
-----+------
01 | 800
01 | 840
01 | 870
01 | 1120
02 | 760
02 | 780
02 | 800
02 | 900
03 | 1200
03 | 1234
03 | 1352
(11 rows)

jeff=# \! cat test_it
drop function test_it_too(text);
create function test_it_too(text)
returns text as '
declare
typ2 alias for $1;
rec record;
string text:= '''';
begin
for rec in select * from test_it where typ = typ2 loop
string := string || rec.diam || '','';
end loop;
string := substr(string, 1, length(string)-1);
return string;
end;
' language 'plpgsql';

jeff=# \i test_it
DROP
CREATE
jeff=# select test_it_too('01');
test_it_too
------------------
800,840,870,1120
(1 row)

> -----Original Message-----
> From: juerg(dot)rietmann(at)pup(dot)ch [SMTP:juerg(dot)rietmann(at)pup(dot)ch]
> Sent: Monday, March 26, 2001 4:13 AM
> To: pgsql-sql(at)postgresql(dot)org
> Subject: Still don't know how to build this string ?
>
> Hello there
>
> I have still the same problem. Any help would really be appreciated !
> Thanks ... jr
>
> Is it possible (and I think it is) to do the following :
>
> I have a table with diameters and types. I need to build a comma separated
> string.
>
> typ diam
> 01 800
> 01 840
> 01 870
> 01 1120
> 02 760
> 02 780
> 02 800
> 02 900
> 03 1200
> 03 1234
> 03 1352
>
> select diam from zylinder where typ='01'
>
> should produce the string "800,840,870,1120"
>
>
>
> ============================================
> PFISTER + PARTNER, SYSTEM - ENGINEERING AG
> Juerg Rietmann
> Grundstrasse 22a
> 6343 Rotkreuz
> Switzerland
>
> phone: +4141 790 4040
> fax: +4141 790 2545
> mobile: +4179 211 0315
> ============================================
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-03-26 17:10:50 Re: is it me or trigger side effects
Previous Message Peter Eisentraut 2001-03-26 17:00:43 Re: Calling Java from psql (was Re: requesting help)