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

If I insert an Option<sqlx::types::Json<Struct>> sqlx writes the text null in DB instead of mark that field as NULL #3294

Closed
frederikhors opened this issue Jun 17, 2024 · 1 comment
Labels

Comments

@frederikhors
Copy link

frederikhors commented Jun 17, 2024

I thought the problem was me and my code and so I tried to reproduce the problem with your code in examples.

I only made minor changes by adding an Option<> to simulate my real problem.

- 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:

- person JSONB NOT NULL
+ person JSONB

If I run it it is saved in the DB:

image

and instead I expect this:

image

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)

I think we can also close these issues after this one (maybe):

  1. JSON Option<> None/Null Behavior #2438

  2. #[sqlx(json)] does not support nullable values #2849

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant