pg icon indicating copy to clipboard operation
pg copied to clipboard

incorrect query marshalling the nil []string to null

Open thetruechar opened this issue 4 years ago • 0 comments

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)

thetruechar avatar Aug 13 '21 11:08 thetruechar