sqlx icon indicating copy to clipboard operation
sqlx copied to clipboard

UNION not supported?

Open felixwatts opened this issue 4 years ago • 3 comments

Hi, not sure if this a bug or expected behaviour or just me misunderstanding how to use UNION, but it would be great if this would work:

This code compiles fine against my DB:

    let notes = sqlx::query_as!(
        Note,
        "
        SELECT * FROM note
        "
    )  
    .fetch_all(conn)
    .await?;

While this one fails

    let notes = sqlx::query_as!(
        Note,
        "
        SELECT * FROM note

        UNION

        SELECT * FROM note
        "
    )  
    .fetch_all(conn)
    .await?;

With compile error:

mismatched types
expected type `i32`
   found enum `std::option::Option<i32>`rustc[E0308](https://doc.rust-lang.org/error-index.html#E0308)
[macros.rs(552, 9): ]()Actual error occurred here
[macros.rs(552, 9): ]()Error originated from macro call here
mismatched types
expected struct `OffsetDateTime`
     found enum `std::option::Option<OffsetDateTime>`rustc[E0308](https://doc.rust-lang.org/error-index.html#E0308)
[macros.rs(552, 9): ]()Actual error occurred here
[macros.rs(552, 9): ]()Error originated from macro call here
mismatched types
expected struct `std::string::String`
     found enum `std::option::Option<std::string::String>`rustc[E0308](https://doc.rust-lang.org/error-index.html#E0308)
[macros.rs(552, 9): ]()Actual error occurred here
[macros.rs(552, 9): ]()Error originated from macro call here

felixwatts avatar Feb 14 '22 13:02 felixwatts

@felixwatts what database are you using?

abonander avatar Mar 23 '22 23:03 abonander

Postgres

felixwatts avatar May 23 '22 06:05 felixwatts

Duplicate of #1266

felixwatts avatar May 26 '22 16:05 felixwatts