1

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)?

1 Answer 1

4

In 8.4 you can use:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.