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

Can't decode nullable values #3683

Open
SorenHolstHansen opened this issue Jan 14, 2025 · 0 comments
Open

Can't decode nullable values #3683

SorenHolstHansen opened this issue Jan 14, 2025 · 0 comments
Labels

Comments

@SorenHolstHansen
Copy link

SorenHolstHansen commented Jan 14, 2025

I have found these related issues/pull requests

#367

Description

sqlx fails to decode any column when the column is nullable.

Reproduction steps

Say i have the following setup in my database

CREATE TABLE table_a (id UUID NOT NULL UNIQUE DEFAULT gen_random_uuid(), name TEXT NOT NULL);

CREATE TABLE table_b (id UUID NOT NULL UNIQUE DEFAULT gen_random_uuid(), name TEXT NOT NULL, thing TEXT, table_a_id UUID);

ALTER TABLE table_b ADD CONSTRAINT table_b_table_a_id FOREIGN KEY (table_a_id) REFERENCES table_a(id) ON DELETE CASCADE ON UPDATE CASCADE;

INSERT INTO table_b (name) VALUES ('name');

Then running the following program

use sqlx::postgres::PgPoolOptions;

#[tokio::main]
async fn main() -> Result<(), sqlx::Error> {
    let pool = PgPoolOptions::new()
        .connect("postgres://postgres:postgres@localhost:5432/testing")
        .await?;

    let row = sqlx::query(
        "
        SELECT
            t.id,
            t.name,
	    t.thing,
            t.table_a_id
        FROM table_b t
        ",
    )
    .fetch_one(&pool)
    .await?;

    println!("ROW {:?}", row);

    Ok(())
}

Prints the following (I have formatted it for readability)

ROW PgRow {
	id: 1f0ae783-4bc1-4424-8605-89e67815f56d, 
	name: "name", 
	thing: (error decoding SQL type TEXT as alloc::string::String: UnexpectedNullError), 
	table_a_id: (error decoding SQL type UUID as uuid::Uuid: UnexpectedNullError)
}

SQLx version

0.8

Enabled SQLx features

runtime-tokio-rustls, postgres, json, uuid

Database server and version

Postgres

Operating system

MacOS

Rust version

1.82.0

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