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
Left join and group by on nullable field returns runtime UnexpectedNullError
error - PostgreSQL, query macros
#3164
Comments
I have tested with |
Please provide the output of |
I've also tried the Here's the query explained as requested: [
{
"Plan": {
"Node Type": "Aggregate",
"Strategy": "Hashed",
"Partial Mode": "Simple",
"Parallel Aware": false,
"Async Capable": false,
"Startup Cost": 88.43,
"Total Cost": 101.13,
"Plan Rows": 1270,
"Plan Width": 44,
"Output": ["count(*)", "providers.id", "providers.name"],
"Group Key": ["providers.id"],
"Planned Partitions": 0,
"Plans": [
{
"Node Type": "Hash Join",
"Parent Relationship": "Outer",
"Parallel Aware": false,
"Async Capable": false,
"Join Type": "Left",
"Startup Cost": 38.58,
"Total Cost": 77.13,
"Plan Rows": 2260,
"Plan Width": 36,
"Output": ["providers.id", "providers.name"],
"Inner Unique": true,
"Hash Cond": "(sources.provider_id = providers.id)",
"Plans": [
{
"Node Type": "Seq Scan",
"Parent Relationship": "Outer",
"Parallel Aware": false,
"Async Capable": false,
"Relation Name": "sources",
"Schema": "public",
"Alias": "sources",
"Startup Cost": 0.00,
"Total Cost": 32.60,
"Plan Rows": 2260,
"Plan Width": 4,
"Output": ["sources.id", "sources.provider_id"]
},
{
"Node Type": "Hash",
"Parent Relationship": "Inner",
"Parallel Aware": false,
"Async Capable": false,
"Startup Cost": 22.70,
"Total Cost": 22.70,
"Plan Rows": 1270,
"Plan Width": 36,
"Output": ["providers.id", "providers.name"],
"Plans": [
{
"Node Type": "Seq Scan",
"Parent Relationship": "Outer",
"Parallel Aware": false,
"Async Capable": false,
"Relation Name": "providers",
"Schema": "public",
"Alias": "providers",
"Startup Cost": 0.00,
"Total Cost": 22.70,
"Plan Rows": 1270,
"Plan Width": 36,
"Output": ["providers.id", "providers.name"]
}
]
}
]
}
]
}
}
] |
UnexpectedNullError
error - PostgreSQLUnexpectedNullError
error - PostgreSQL, query macros
I've run into this issue a couple times |
A column should be nullable during left joins that but the generated query-<hash>.json marks the column as nullable false and then I get the error |
Bug Description
When doing a left join between two tables on a field that is nullable and performing a group by on the joined table field, a
UnexpectedNullError
is returnedMinimal Reproduction
The following is a simplified reproduction from my current project:
The following query within SQLx errors but should return valid data:
Value of
fetch_all
return:Query data using an external DB tool:
I alter the query to reference the original table only, everything works:
Value of
fetch_all
return:But since I want the other field (
name
) from the other table, I cannot/do not want to do the last query.Info
0.7.4
["chrono", "json", "macros", "postgres", "runtime-tokio-native-tls", "uuid"]
postgres:16.2-alpine3.19
image)rustc --version
:rustc 1.77.0 (aedd173a2 2024-03-17)
(running within docker with therust:1.77.0-slim-bookworm
image)The text was updated successfully, but these errors were encountered: