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

Support for JSON field selectors (data->"$.a.b.c") #375

Open
skolodyazhnyy opened this issue Oct 5, 2024 · 1 comment
Open

Support for JSON field selectors (data->"$.a.b.c") #375

skolodyazhnyy opened this issue Oct 5, 2024 · 1 comment

Comments

@skolodyazhnyy
Copy link
Contributor

MySQL allows querying a property from a JSON field using special syntax, for example, like so SELECT col->"$.mascot" FROM qtest. In our system, we use normal columns to narrow down results to just a few hundreds rows, but then apply a few JSON filters to further filter and sort records based on the values in the JSON fields. The value stored in JSON is dynamic, and it's not feasible to extract it into a column.

The query looks something like this:

SELECT * FROM records WHERE scope = ? AND data->'$.r_12345' != 0 ORDER BY data->'$.r_12345' ASC

I can add a filter by JSON field using rel.FilterFragment API, but unfortunately, there is nothing similar for ORDER BY portion.

What would be the best way to implement it, and is there a workaround? For example, adding support for col->"..." to a field escape function or maybe just adding support for rel.OrderFragment?

@skolodyazhnyy
Copy link
Contributor Author

Found workaround rel.SortAsc("^col->'$.mascot'"), still wonder if this might be useful as rel feature.

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

No branches or pull requests

1 participant