Output = enterprise I need to use BTRIM function to trim the double quotes like above, with jsonb_array_elements f" /> Output = enterprise I need to use BTRIM function to trim the double quotes like above, with jsonb_array_elements f" /> Output = enterprise I need to use BTRIM function to trim the double quotes like above, with jsonb_array_elements f"/>

Use Trim Function With jsonb_array_elements in PostgreS

61 views Asked by At
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

column
"Value1"
"Value2"
"Value3"

I need the output without double quotes like below.

column
Value1
Value2
Value3
2

There are 2 answers

0
SelVazi On BEST ANSWER

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
1
Anthony Sotolongo On

I think that you can use the BTRIM function to remove the " to the output of jsonb_array_elements casted to text:

SELECT BTRIM ((jsonb_array_elements(json_column->'Fields')->'field_name')::text,'"') as "column"
FROM table_a