简体   繁体   中英

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?

这应该可以解决问题,至少这是我所了解的:

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM