In postgres, how can I convert json array of integers to postgres int4[]?
- User
In postgres, how can I convert json array of integers to postgres
int4[]? Assistant
To convert a JSON array of integers to a PostgreSQL
int4[]array, you can use:sqlSELECT json_column::int[] FROM your_table;For more control, you can use:
sqlSELECT ARRAY( SELECT jsonb_array_elements_text(json_column)::int FROM your_table );Or with a subquery pattern:
sqlSELECT array_agg(value::int) FROM json_array_elements_text(json_column) AS elements(value);Would you like me to explain or break down the code?
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.