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

incorrect query marshalling the nil []string to null #1908

Open
thetruechar opened this issue Aug 13, 2021 · 0 comments
Open

incorrect query marshalling the nil []string to null #1908

thetruechar opened this issue Aug 13, 2021 · 0 comments

Comments

@thetruechar
Copy link

thetruechar commented Aug 13, 2021

create table settings
(
    aspects      jsonb       default '[]'::jsonb,
);
var a []string
Db.Query( &ss, `select * from settings where aspects @> coalesce(?, '[]'::jsonb)`, a)

the query msg will become:

select * from settings where aspects @> coalesce('null', '[]'::jsonb)

not what I expect:

select * from settings where aspects @> coalesce(null, '[]'::jsonb)

only the literal nil work:

var a []string
Db.Query( &ss, `select * from settings where aspects @> coalesce(?, '[]'::jsonb)`, nil)

results:

select * from settings where aspects @> coalesce(null, '[]'::jsonb)
elliotcourant added a commit to elliotcourant/pg that referenced this issue Nov 20, 2021
When a query parameter was a nil slice or a nil map, the value `NULL`
would not be appended to the query. Instead `'null'` would be appended
to the query which is not correct.

Resolves go-pg#1908
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

Successfully merging a pull request may close this issue.

1 participant