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

前端 未结 3 559
灰色年华
灰色年华 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:00

    PostgreSQL provides two native operators -> and ->> to help you query JSON data.

    The operator -> returns JSON object field as JSON. The operator ->> returns JSON object field as text.

    The following query uses operator -> to get all customers in form of JSON:

    SELECT
     info -> 'customer' AS customer
    FROM
     orders;
    
    customer
    --------
    "John Doe"
    "Lily Bush"
    "Josh William"
    "Mary Clark"
    

    And the following query uses operator ->> to get all customers in form of text:

    SELECT
     info ->> 'customer' AS customer
    FROM
     orders;
    
    customer
    --------
    John Doe
    Lily Bush
    Josh William
    Mary Clark
    

    You can see more details in the link below http://www.postgresqltutorial.com/postgresql-json/

提交回复
热议问题