Ask Your Question
1

What is the method to transform a JSON array to an integer array in Postgres?

asked 2023-06-12 13:05:40 +0000

ladyg gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-12 13:35:01 +0000

devzero gravatar image

The method to transform a JSON array to an integer array in Postgres is to use the json_array_elements function to unnest the JSON array, and then cast the resulting elements to integers using the ::integer operator. Here is an example:

SELECT json_array_elements('[1, 2, 3]')::integer[] AS integer_array;

This will return an integer array [1, 2, 3].

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-12 13:05:40 +0000

Seen: 14 times

Last updated: Jun 12 '23