sqlx::query_as!() returns unexpected null; try decoding as an Option
when multiple (left) joins are used
#3202
Labels
Option
when multiple (left) joins are used
#3202
Bug Description
I found I had to use the
col as "col?"
trick to force nullability at runtime otherwisesqlx::query_as!()
produces "unexpected null; try decoding as anOption
when multiple (left) joins are used".The documentation for
sqlx::query_as!()
requests a bug report be filed in such cases.Minimal Reproduction
The application in question tracks the weekly top 50 of radio stations.
The two tables needed to reproduce this are as follows:
The query involved:
The fields
prev_position
anddelta
are null if the track was not present in the previous week's top50.Then looking at the
nullability
field in the files produced bycargo sqlx prepare
I have also noticed that it produces afalse
for theprev_position
field and anull
for thedelta
field.For completeness sake, here is the struct I'm using
query_as!
to decode the rows into:The query plan:
Info
["postgres", "runtime-tokio", "migrate", "chrono"]
rustc --version
:rustc 1.77.2 (25ef9e3d8 2024-04-09)
The text was updated successfully, but these errors were encountered: