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

Problem with JSON function encoding #171

Closed
fabriciogpp opened this issue Oct 9, 2024 · 2 comments
Closed

Problem with JSON function encoding #171

fabriciogpp opened this issue Oct 9, 2024 · 2 comments
Labels

Comments

@fabriciogpp
Copy link

fabriciogpp commented Oct 9, 2024

I'm trying to upgrade from v1.27.3 to v1.30.0 and it is giving me this issue.

I have this statement composing my query:

sb.Equal("data->'$.some.field'", 123)

And it encoded it like this:

SELECT COUNT(*) FROM table WHERE id = ? AND deleted_at IS NULL AND data->'$$.some.field' = ?

Which produced this error:

Error 3143 (42000): Invalid JSON path expression. The error is around character position 1.

Note the double $$ in the query.

I manually replaced it with strings.ReplaceAll(qry, "$$", "$") and the query worked again.

Is this a bug or I'm missing something?


Edit: with version v1.29.0 works fine. It is a problem with v1.30.0.


(my driver is github.com/go-sql-driver/mysql v1.8.1)
(full builder code would be something like this:)

sb := sqlbuilder.Select("COUNT(*)").From("table")
where := []string{ sb.Equal("data->'$.some.field'", 123), /* more... */}
qry, args := sb.Where(where...).Build()
@huandu
Copy link
Owner

huandu commented Oct 10, 2024

It's a bug. Thanks for reporting this to me.

@huandu huandu added the bug label Oct 10, 2024
@huandu huandu closed this as completed in c329655 Oct 10, 2024
@huandu
Copy link
Owner

huandu commented Oct 10, 2024

Fixed in tag v1.30.1.

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

No branches or pull requests

2 participants