From: | Michael Fork <mfork(at)toledolink(dot)com> |
---|---|
To: | juerg(dot)rietmann(at)pup(dot)ch |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Still don't know how to build this string ? |
Date: | 2001-03-26 14:49:46 |
Message-ID: | Pine.BSI.4.21.0103260942010.11964-100000@glass.toledolink.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
The following function will convert a given list into a comma delimited
string (the argument should be the typ):
CREATE FUNCTION dima_list(int4) RETURNS text AS '
DECLARE
rec record;
list text;
BEGIN
list := '''';
FOR rec IN SELECT diam FROM zylinder WHERE typ = $1
list := list || rec.diam || ''; ''
END LOOP;
RETURN list;
END;
' LANGUAGE 'plpgsql';
Note that PL/PGSQL must be installed first, which can be done by typing
createlang plpgsql
at a shell prompt as a postgres super user.
Michael Fork - CCNA - MCP - A+
Network Support - Toledo Internet Access - Toledo Ohio
On Mon, 26 Mar 2001 juerg(dot)rietmann(at)pup(dot)ch wrote:
> 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
>
From | Date | Subject | |
---|---|---|---|
Next Message | Najm Hashmi | 2001-03-26 15:41:15 | is it me or trigger side effects |
Previous Message | Cedar Cox | 2001-03-26 13:44:56 | Re: Functions and Triggers |