What is the difference between `->>` and `->` in Postgres SQL?

前端 未结 3 543
灰色年华
灰色年华 2020-12-24 04:19

What is the difference between ->> and -> in SQL?

In this thread (Check if field exists in json type column postgresql), the answe

3条回答
  •  温柔的废话
    2020-12-24 05:14

    -> returns json(b) and ->> returns text:

    with t (jo, ja) as (values
        ('{"a":"b"}'::jsonb,('[1,2]')::jsonb)
    )
    select
        pg_typeof(jo -> 'a'), pg_typeof(jo ->> 'a'),
        pg_typeof(ja -> 1), pg_typeof(ja ->> 1)
    from t
    ;
     pg_typeof | pg_typeof | pg_typeof | pg_typeof 
    -----------+-----------+-----------+-----------
     jsonb     | text      | jsonb     | text
    

提交回复
热议问题