Abdalla Ismail
Abdalla Ismail

Reputation: 409

Choosing row based on json value sql

I have a column which saves json values as text. I want to select columns in query based on a certain value contained in the text field.

To be clear, I have a column server_response which saves data as follows:

{ "Success": true, "PasswordNotExpired": true, "Exists": true, "Status": "A", "Err": null, "Statuscode": 200, "Message": "Login Denied" }

How can i choose columns based on if the message was/or contained Login Denied in the where clause?

Upvotes: 1

Views: 64

Answers (2)

shA.t
shA.t

Reputation: 16958

I think you need a query like this:

SELECT *
FROM yourTable
WHERE server_response->>Message LIKE '%Login Denied%'

Note: source

The -> operator returns a JSON object.
The ->> operator returns TEXT.

Upvotes: 1

Raul Cuth
Raul Cuth

Reputation: 2469

This should do the trick, at least this is what i understood you want:

SELECT * FROM table WHERE server_response LIKE '%Login Denied%'

Upvotes: 4

Related Questions