1

I have a table that looks like this

+------+------------------------------------+
|  id  |              details               |
+------+------------------------------------+
|   1  | {"price":"24.99","currency":"USD"} |
+------+------------------------------------+

Is it possible to, with a single MySQL select statement, obtain the value of price 24.99?

2

1 Answer 1

1

Yes, you can using JSON_EXTRACT

It probably should be like:

SELECT JSON_EXTRACT(details, "$.price")
FROM table_name

or another form:

SELECT details->"$.price"
FROM table_name

(I don't have MySql to test it)

Note that the price in your JSON stored as a string, not a number and you probably would want to cast it to a DECIMAL.

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

1 Comment

Ahh MySQL 5.7...now to wait for Google Cloud to support it :)

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.