Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSON_EXTRACT function does not get the expected result #29673

Closed
Kongdom opened this issue Nov 11, 2021 · 3 comments · Fixed by #29750
Closed

JSON_EXTRACT function does not get the expected result #29673

Kongdom opened this issue Nov 11, 2021 · 3 comments · Fixed by #29750

Comments

@Kongdom
Copy link

Kongdom commented Nov 11, 2021

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

SELECT JSON_EXTRACT('{"properties": {"$type": "TiDB"}}','$.properties.$type')

2. What did you expect to see? (Required)

"TiDB"

3. What did you see instead (Required)

{"$type": "TiDB"}

4. What is your TiDB version? (Required)

5.7.25-TiDB-v5.1.0

@Kongdom Kongdom added the type/bug The issue is confirmed as a bug. label Nov 11, 2021
@Kongdom
Copy link
Author

Kongdom commented Nov 11, 2021

When using the JSON_EXTRACT function, if the name of the json field contains the $ symbol, you will not get the expected result.
For example, the following statement outputs valid results in MySQL and invalid results in TiDB.

SELECT JSON_EXTRACT('{"properties": {"$type": "TiDB"}}','$.properties.$type')

However, it is valid in TiDB to write the following instead, just adding the quotes.

SELECT JSON_EXTRACT('{"properties": {"$type": "TiDB"}}','$.properties."$type"')

Although, the expected result can be obtained by the above writing, I still hope that TiDB will be compatible with the initial writing and reduce the syntax difference between TiDB and MySQL.

Finally, technology connects you and me, code creates the future!

@znhh6018
Copy link
Contributor

/assign

@github-actions
Copy link

Please check whether the issue should be labeled with 'affects-x.y' or 'fixes-x.y.z', and then remove 'needs-more-info' label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants