'How to convert integer[] to jsonb in a PL/pgSQL code block

How to convert integer[] to jsonb?

declare ids int[];
declare jsonids jsonb;

jsonids := array(select id from student); -- what should I do here?


Solution 1:[1]

You can try this

select array_to_json(array_agg(id)) into jsonids from student

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Philippe