-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
sqlx prepare
fails with error "unsupported type NULL of column #2"
#1979
Comments
Thanks for the schema & query, I've added a [partial] fix into PR #1960 fixing a smaller reproducer. That fix doesn't seem to work for your query though, so there are still issues remaining after that. |
I also have a query that fails for this exact error. I can't isolate a minimum example, but this is my project commit: Hopefully it is not too large. The same query |
I got the same error also after factoring out the WITH clause into a view. The view's column type seems to be NULL for the |
@rongcuid my app is also using SQLite. I wonder if sqlx has more difficulty checking types when the db is SQLite? |
I know next to nothing about the other sqlx database backends. But sqlite does have some tricky calculations/trade-offs to do when it attempts to do type checking. Long story short... sqlite does not appear to have any high-level API to find query result types/nullability without running the query. So sqlx inspects a low-level query plan from sqlite instead, sqlx then infers/traces through that query plan to determine the types. Unrecognized operations can cause type information to be lost. When that type information is lost, it can cause sqlx to not know which type a column is (ie. column type NULL). I'm out of time this week. But I am guessing that the issue with @rongcuid's query is due to the row_number() function being unrecognized. But tat's just a hunch, if you dig in you may find I'm mistaken, or even find that there are multiple issues at play. |
@tyrelr I noticed that the In my app buyers put ratings on orders. When I run
But after I put at least one rating in the database, it works again:
|
That's interesting, @yzernik. Nothing on the macro side inspects actual data rows within the tables, as far as I'm aware. Sqlx retrieves the declared table column types, and the query plan, and all calculations are based on those inputs. Based on that, I wouldn't expect the presence of data within a table to impact the outcome of the check. But I believe if the non-empty database has statistics, i suppose the query optimizer COULD select a different query plan, and that alternate query plan may be lucky enough to avoid this bug? |
I realized that I can use "query" instead of "query!" for the queries where type inference fails as a workaround for now. Is it expected that these queries will work in v0.7? |
Just ran into the same sort of error using
I was still able to use |
I'm running into the same issue I believe. I have a small reproducible example using SQLite Here's some relavent info cargo.toml
main.rs #[actix_web::main]
async fn main() -> std::io::Result<()> {
// .env file with DATABASE_URL=sqlite:sqlite.db
let pool = SqlitePool::connect("sqlite.db").await.unwrap();
let mut conn = pool.acquire().await.unwrap();
sqlx::query!(
r#"
CREATE TABLE IF NOT EXISTS Ads (
company,
position,
remote,
apply_link,
description,
paid
)
"#
)
.execute(&mut conn)
.await
.unwrap();
// insert data here if you wish
let res = sqlx::query!(r#"select company, position from Ads"#)
.fetch_all(&pool)
.await
.unwrap();
Ok(())
} You'll get these errors
glad to provide any more information if needed. |
I have a query that in my master branch works fine, but when I try to modify the query to add some additional clauses, the
sqlx prepare
command fails with:This is the query, and this is the pull request that is failing.
Related to #1350
The text was updated successfully, but these errors were encountered: