Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Use Trim Function With jsonb_array_elements in PostgreS

SELECT BTRIM('"enterprise"', '"') 
> Output = enterprise

I need to use BTRIM function to trim the double quotes like above, with jsonb_array_elements function.

I have a query like below,

SELECT jsonb_array_elements(json_column->'Fields')->'field_name' as "column"
FROM table_a

Which returns

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

column
"Value1"
"Value2"
"Value3"

I need the output without double quotes like below.

column
Value1
Value2
Value3

>Solution :

Trim function is not required, just use ->> to get JSON array elements as text :

SELECT jsonb_array_elements(json_column->'Fields')->>'field_name' as "column"
FROM table_a
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading