skip to Main Content
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

Answers


  1. 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
    
    Login or Signup to reply.
  2. 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
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search