I want to dynamically concat strings in a jsonb array in my psql query which is as follows :
with cte as (select generate_series(1, 3) as num) select '["name", "number"||cte.num]'::jsonb as res from cte;
But I am getting this error :
ERROR: invalid input syntax for type json
LINE 1: ...e as (select generate_series(1, 5) as num) select '["name", ...
^
DETAIL: Token "|" is invalid.
CONTEXT: JSON data, line 1: ["name", "number"|...
So, here I am generating numbers from 1 to 3 and I want to append those numbers with "number" string in my jsonb array. This is what I want in my result:
res
----------------------
["name", "number1"]
["name", "number2"]
["name", "number3"]
Please tell me how do I get this. Thanks.
concat_ws()Function.