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 query with boolean argument fails #7005

Open
andersryanc opened this issue Apr 30, 2024 · 0 comments
Open

json query with boolean argument fails #7005

andersryanc opened this issue Apr 30, 2024 · 0 comments
Assignees
Labels
type:with reproduction steps with reproduction steps

Comments

@andersryanc
Copy link

andersryanc commented Apr 30, 2024

GORM Playground Link

go-gorm/playground#729

Description

When querying a property inside a json field with a bool argument, the query returns 0 rows. However, if you embed the bool into the where clause itself, you get 1 row. The strange thing is that the generated SQL shown by the debugger is identical.

Broken Example:

DB.Where("config->'enabled' = ?", true).Find(&results)
2024/04/30 11:20:10 /__REDACTED__/playground/main_test.go:108
[0.847ms] [rows:0] SELECT * FROM `accounts` WHERE config->'$.enabled' = true

Working Example:

DB.Where("config->'enabled' = true").Find(&results)
2024/04/30 11:20:10 /__REDACTED__/playground/main_test.go:108
[0.647ms] [rows:1] SELECT * FROM `accounts` WHERE config->'$.enabled' = true

I tried testing a variety of other variations as well, like using json_extract and the double arrow syntax, like config->>'$.enabled'. The same thing also happens with nested values, such as config->'$.foo.enabled' = true.

@github-actions github-actions bot added the type:missing reproduction steps missing reproduction steps label Apr 30, 2024
@github-actions github-actions bot added type:with reproduction steps with reproduction steps and removed type:missing reproduction steps missing reproduction steps labels Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:with reproduction steps with reproduction steps
Projects
None yet
Development

No branches or pull requests

2 participants