How to convert integer[] to jsonb?
declare ids int[];
declare jsonids jsonb;
jsonids := array(select id from student); -- what should I do here?
How to convert integer[] to jsonb?
declare ids int[];
declare jsonids jsonb;
jsonids := array(select id from student); -- what should I do here?
 
    
     
    
    Use to_jsonb():
jsonids := to_jsonb(ARRAY(SELECT id FROM student));
Or:
SELECT INTO jsonids to_jsonb(ARRAY(SELECT id FROM student));
array_to_json() is only still useful to get line feeds in json (not jsonb!). The manual:
Converts an SQL array to a JSON array. The behavior is the same as
to_jsonexcept that line feeds will be added between top-level array elements if the optional boolean parameter is true.
See:
To convert back:
 
    
    You can try this
select array_to_json(array_agg(id)) into jsonids from student
