sql.json(null)
should produce 'null'::jsonb
instead of null
#317
Labels
sql.json(null)
should produce 'null'::jsonb
instead of null
#317
Expected Behavior
The query
should result in the SQL
Current Behavior
The above query actually gets translated to
NULL
and'null'::jsonb
are different, and this can have a bad side effect such as when usingjsonb_set
. In the following example, we have a jsonb{"key": "value"}
, and try to set the value tonull
, which should result in a new jsonb{"key": null}
However, it actually results in
NULL
instead of{"key": null}
since Slonik passes inNULL
instead of'null'::jsonb
. Note that you could also simply pass in the string'null'
and it would be implicitly casted to jsonb here.Possible Solution
I haven't followed the code path for how
sql.json
gets translated, but I did find a test case that is specifically checkingnull
but expecting what I consider an incorrect result.The test is:
but I believe it should be:
Workaround
I ran into this issue when trying to do something like
where
value
can sometimes be null. Instead I've rewritten this as:The ternary works, but it would be simpler if
sql.json
handlednull
differently.The text was updated successfully, but these errors were encountered: