-
Notifications
You must be signed in to change notification settings - Fork 17
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
Invalid SQL generated for JSON fragment #21
Comments
Thanks for the report. as I pointed here #20 (comment), Ecto doesn't provide information about types in its telemetry events, so Even if ecto sends info about type, it is not really possible to detect proper type in case of fragments. This is a workaround from m in "test", select: 1, where: fragment(~s(?#>'{field}' @> ? :: json), m.details, ^Jason.encode!([%{id: 1}]))
# SELECT TRUE FROM "test" AS t0 WHERE (t0."details"::jsonb#>'{field}' @> '[{"id":1}]' :: json) but it's up to you whether to use it or not, as this is only for logging purpose |
@fuelen I'm running into a similar issue as the above, but specifically with an I've only poked around a little bit, but it appears that In practice, I don't know if this is a good idea, but I wanted to put it out there to see if it inspired anything. |
@vanderhoop I'm afraid this won't work as well, as the schema can have multiple embedded schemas :) |
Specifically, the array brackets have been turned into braces and the quotes were incorrectly escaped, the generated SQL should be:
SELECT ... FROM "model" AS m0 WHERE (m0."details"#>'{field}' @> '[{"id":1}]')
The text was updated successfully, but these errors were encountered: