I thought the problem was me and my code and so I tried to reproduce the problem with sqlx example directly.
I only made minor changes by adding an Option<>
to simulate my real problem.
<code>- async fn add_person(pool: &PgPool, person: Person) -> anyhow::Result<i64> {
+ async fn add_person(pool: &PgPool, person: Option<Person>) -> anyhow::Result<i64> {
</code>
<code>- async fn add_person(pool: &PgPool, person: Person) -> anyhow::Result<i64> {
+ async fn add_person(pool: &PgPool, person: Option<Person>) -> anyhow::Result<i64> {
</code>
- async fn add_person(pool: &PgPool, person: Person) -> anyhow::Result<i64> {
+ async fn add_person(pool: &PgPool, person: Option<Person>) -> anyhow::Result<i64> {
and in migrations
:
<code>- person JSONB NOT NULL
+ person JSONB
</code>
<code>- person JSONB NOT NULL
+ person JSONB
</code>
- person JSONB NOT NULL
+ person JSONB
If I run it it is saved in the DB:
and instead I expect this:
Where am I doing wrong?
Minimal Reproduction
https://github.com/frederikhors/iss-sqlx-option-null
Info
- SQLx version:
"0.7.4"
- SQLx features enabled:
"macros", "postgres", "runtime-tokio", "chrono", "uuid"
- Database server and version:
Postgres 16
- Operating system:
Windows
rustc --version
:rustc 1.79.0 (129f3b996 2024-06-10)