开发者

Problem using any operator in plpgsql function

When i run this function:

CREATE OR REPLACE FUNCTION insert_styles(raw_styles text)
  RETURNS integer AS
$BODY$
declare
    arr_value TEXT[];
    upper_limit INTEGER;    
    style_ids INTEGER[];
    BEGIN
        arr_value   := string_to_array(raw_styles, ',');
        upper_limit := array_upper(arr_value, 1);

        RAISE NOTICE 'arr_value = %', arr_value;
        SELECT music_style FROM music_style INTO style_ids WHERE name = ANY (arr_value);
        RETURN upper;
    END;
$BODY$
  LANGUAGE plpgsql VOLATILE
  COST 100;

with this query:

SELECT insert_styles('Techno,ddd,wer,WJKDF');

It gives me the following error:

NOTICE:  arr_v开发者_如何学Goalue = {Techno,ddd,wer,WJKDF}
ERROR:  array value must start with "{" or dimension information
CONTEXT:  PL/pgSQL function "insert_styles" line 10 at SQL statement

I just can't figure it out. I'am a postgres newbie!

bye!!


Assuming that your music_style column has integer datatype you just need to add array_agg aggregate into your query:

SELECT array_agg(music_style)
FROM music_style
INTO style_ids -- style_ids is integer[]
WHERE name = ANY (arr_value);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜