3

I have JSON stored in a jsonb column:

{
  "processedResult": {
    "orderPayment": {
      "paymentType": "VISA"
    },
    "store": "US"
  }
}

What I have tried:


SELECT DISTINCT myData -> 'processedResult' -> 'orderPayment' -> 'paymentType' 
FROM mytable
WHERE myData ->> 'processedResult' ->> 'store'  = 'US'

The WHERE clause seems to be incorrect.

Desired Output:

VISA
Mastedcard

Postgres Version: PostgreSQL 11.13

1 Answer 1

6

You'll want to use

SELECT DISTINCT myData -> 'processedResult' -> 'orderPayment' ->> 'paymentType' 
FROM mytable
WHERE myData -> 'processedResult' ->> 'store'  = 'US'

Notice that -> returns the selected jsonb value, whereas ->> always returns a postgres text value (or NULL, or an error).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.