Join the Stack Overflow Community
Stack Overflow is a community of 6.3 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I need to convert a comma separated text into a set of records. I created this function but I am not convinced that the best way:

CREATE OR REPLACE FUNCTION F_StringListToRecord(pStringList TEXT, pDelimiter VARCHAR(10)) RETURNS SETOF RECORD AS $$
DECLARE
  vIndex INT;
  arrSize INT;
  arrValue TEXT[];
BEGIN
  arrValue := STRING_TO_ARRAY(pStringList, pDelimiter);
  arrSize := ARRAY_UPPER(arrValue, 1);
  FOR vIndex IN 1..arrSize LOOP
    RETURN QUERY SELECT arrValue[vIndex];
  END LOOP;
END $$
LANGUAGE plpgsql;

Is there any other function similar to STRING_TO_ARRAY (perhaps STRING_TO_RECORD)?

share|improve this question

In 8.4 you can use:

select * from unnest(string_to_array(my_string_here,delimiter)) as v(x);

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.