Re: Function returning SETOF - Mailing list pgsql-general

From Tony Caduto
Subject Re: Function returning SETOF
Date
Msg-id 438F563B.10109@amsoftwaredesign.com
Whole thread Raw
In response to Function returning SETOF  (Terry Lee Tucker <terry@esc1.com>)
List 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

pgsql-general by date:

Previous
From: Johan
Date:
Subject: Re: Disk Keeper
Next
From: "John D. Burger"
Date:
Subject: Re: Finding uniques across a big join