Search Postgresql Archives

Re: Function returning SETOF

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux