开发者

Postgres STRING_TO_ARRAY alternative? Like STRING_TO_RECORD?

开发者 https://www.devze.com 2023-01-09 23:37 出处:网络
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:

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 $$
DEC开发者_如何学JAVALARE
  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)?


In 8.4 you can use:

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

0

精彩评论

暂无评论...
验证码 换一张
取 消