How to extract text from jsonb array in postgresql?

Member

by brandy , in category: MySQL , 8 months ago

How to extract text from jsonb array in postgresql?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by ryleigh , 8 months ago

@brandy 

To extract text from a JSONB array in PostgreSQL, you can use the json_array_elements_text function. This function takes a JSONB array as input and returns each element of the array as text.


Here is an example:

1
SELECT json_array_elements_text('["apple", "banana", "orange"]'::jsonb);


This will return:

1
2
3
4
5
json_array_elements_text 
-------------------------
apple
banana
orange


You can also use the jsonb_array_elements_text function if you are working directly with a JSONB column in a table:

1
SELECT jsonb_array_elements_text(jsonb_column_name) FROM table_name;


This will return each element of the JSONB array stored in the jsonb_column_name column of the table_name table as text.

Related Threads:

How to push to an array inside of a json object in a jsonb column in postgresql?
How to update jsonb string with postgresql?
How to order by on a key inside jsonb column in postgresql?
How to query nested jsonb format data column in postgresql?
How to dynamically extract numbers before text with regex?
How to extract text between two words in oracle?