From: | Tony Caduto <tony_caduto(at)amsoftwaredesign(dot)com> |
---|---|
To: | Terry Lee Tucker <terry(at)esc1(dot)com> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Function returning SETOF |
Date: | 2005-12-01 19:59:55 |
Message-ID: | 438F563B.10109@amsoftwaredesign.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Terry Lee Tucker wrote:
>List,
>
>I have a simple function:
>CREATE OR REPLACE FUNCTION parse_string (TEXT, TEXT) RETURNS SETOF TEXT AS '
>DECLARE
> str ALIAS FOR $1; -- the string to parse
> delimiter ALIAS FOR $2; -- the delimiter
> field TEXT; -- return value from split_part
> idx INTEGER DEFAULT 1; -- field counter
> funcName TEXT DEFAULT ''parse_string''; -- function name
> dbg BOOLEAN DEFAULT True; -- debug print flag
>BEGIN
> IF dbg THEN
> RAISE NOTICE ''% ()'', funcName;
> END IF;
> SELECT INTO field split_part (str, delimiter, idx);
> WHILE field != '''' LOOP
> RETURN NEXT field;
> idx = idx + 1;
> SELECT INTO field split_part (str, delimiter, idx);
> END LOOP;
> RETURN;
>END;
>' LANGUAGE 'plpgsql';
>
>As you can see, I'm using split_part to parse the string in a loop. I want
>this thing to return the set of values that make up the fields in the string.
>
>
Why not try a temp table and a ref cursor?
dump the split values into the temp table and return the ref cursor.
Tony Caduto
AM Software Design
Home of PG Lightning Admin
http://www.amsoftwaredesign.com
From | Date | Subject | |
---|---|---|---|
Next Message | John D. Burger | 2005-12-01 20:15:01 | Re: Finding uniques across a big join |
Previous Message | Johan | 2005-12-01 19:43:27 | Re: Disk Keeper |