PostgreSQL: Issue with passing array to procedure

后端 未结 2 1579
悲哀的现实
悲哀的现实 2020-12-22 08:46

I have a type as:

CREATE TYPE status_record AS
   (
   id bigint,
   status boolean
   );

A procedure that does some processing with an arr

相关标签:
2条回答
  • 2020-12-22 09:42

    Use an array literal (text representation of the array), since the array constructor ARRAY[...] has to be evaluated by Postgres:

    SELECT update_status('{"(1,t)","(2,f)"}'::status_record[]);
    

    Maybe even without the explicit cast:

    SELECT update_status('{"(1,t)","(2,f)"}');
    

    There were similar cases on SO before:

    • Pass array from node-postgres to plpgsql function
    • How to pass custom type array to Postgres function
    0 讨论(0)
  • 2020-12-22 09:51

    Try to put the array and type initialization into a string, maybe you can then get around the problems with the obfuscation layer (aka ORM):

    select update_status(cast('{"(1,true)", "(2,false)"}' as status_record[]));
    

    I don't know Hibernate, so I can't tell if that will work.

    0 讨论(0)
提交回复
热议问题