postgresql - Converting a returned SETOF into An Array in PL/PgSQL (specifically) -
i know there process of select array_agg(f) (select blah stuff) f
, great in sql, when writing functions in pl/pgsql, there shorthand method??
i'm trying put json keys array can use @ length. like...
v_len := array_length( array_agg(json_object_keys(myjson)), 1);
instead of long, declare variable, select array_agg(f) ...
, i've been doing. i've seem hundreds of implementations using same sql string, want cut down code, fingers going numb redundant typing.
what missing shorthand method?
you can use array(subselect) constructor
do $$ declare int[]; begin := array(select * generate_series(1,10)); raise notice 'result: %', a; end; $$;
Comments
Post a Comment