Skip to content

Instantly share code, notes, and snippets.

@joesavak
Created December 14, 2010 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joesavak/740683 to your computer and use it in GitHub Desktop.
Save joesavak/740683 to your computer and use it in GitHub Desktop.
CREATE OR REPLACE FUNCTION getDelimRow(p_slct character varying, p_dlmtr character varying DEFAULT ','::character varying)
RETURNS character varying AS
$BODY$
DECLARE
cur1 refcursor;
lc_str VARCHAR(4000);
lc_colval VARCHAR(4000);
intervalNum INTEGER;
BEGIN
intervalNum := 0;
OPEN cur1 FOR execute(p_slct);
LOOP
FETCH cur1 INTO lc_colval;
if not found then
exit;
end if;
IF intervalNum = 0 THEN
lc_str:= lc_colval;
intervalNum := 1;
ELSE
lc_str := lc_str || p_dlmtr || lc_colval;
END IF;
END LOOP;
CLOSE cur1;
RETURN lc_str;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment