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

bug: integer doesn't get decoded properly if the previous value is null #104

Closed
PoiScript opened this issue Jan 31, 2020 · 1 comment
Closed
Labels
bug db:postgres Related to PostgreSQL

Comments

@PoiScript
Copy link
Contributor

PoiScript commented Jan 31, 2020

SQL:

CREATE TABLE foo (
  id TEXT PRIMARY KEY,
  bar INTEGER,
  baz INTEGER
);
INSERT INTO foo (id, bar, baz) VALUES ('001', 100, 100);
INSERT INTO foo (id, bar, baz) VALUES ('002', null, 100);

Rust:

struct Foo {
    bar: Option<i32>,
    baz: Option<i32>,
}

let mut pool = PgPool::new(env!("DATABASE_URL")).await.unwrap();

let row = sqlx::query_as!(Foo, "select bar, baz from foo where id = '001'")
    .fetch_one(&mut pool)
    .await
    .unwrap();

assert_eq!(row.bar, Some(100));
assert_eq!(row.baz, Some(100));

let row = sqlx::query_as!(Foo, "select bar, baz from foo where id = '002'")
    .fetch_one(&mut pool)
    .await
    .unwrap();

assert_eq!(row.bar, None);
assert_eq!(row.baz, Some(100)); // error 

Error:

thread 'main' panicked at 'assertion failed: `(left == right)`
  left: `Some(4)`,
 right: `Some(100)`', src/main.rs:64:5

FYI, I'm using PostgreSQL 12.1 on ArchLinux.

@mehcode mehcode closed this as completed in 7201f63 Feb 1, 2020
@mehcode
Copy link
Member

mehcode commented Feb 1, 2020

Thanks for the issue report. This has been fixed and is out with v0.2.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug db:postgres Related to PostgreSQL
Projects
None yet
Development

No branches or pull requests

2 participants