Re: Function returning SETOF
От | Tony Caduto |
---|---|
Тема | Re: Function returning SETOF |
Дата | |
Msg-id | 438F563B.10109@amsoftwaredesign.com обсуждение исходный текст |
Ответ на | Function returning SETOF (Terry Lee Tucker <terry@esc1.com>) |
Список | 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 по дате отправления: