You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know the types in this example are all messed up. I'm in a huge rush and don't have time to file the issue with extreme precision at this moment.
You can see in the playground link because the type is non nullable in the table, it incorrectly assumes that the subselect can never return null for that field.
typeTestRowstruct {
Otherfield sql.NullStringName decimal.NullDecimal// note the difference here
}
The first struct (the one sqlc generates and is in my playground link) is incorrect. This valid query cannot properly be bound to this struct for all possible return values (as the subquery can return null). Does that make it more clear?
Your example is working I agree. However I could only reproduce when using type overrides which your example does not include. Please take another look.
I am also having the same problem. Even if I reflect the type in sqlc.yml in the subquery results, it is not applied. Could you please check this Issue again?
@WesleyMiller1998 I agree this issue configuration and generation seems to works fine; as the override is done at the database data type. However, your issue #1752 the override requested is by column name and it does have a bug. @kyleconroy I propose this issue to be closed.
Until Name is generated as a decimal.NullDecimal (as per the config for the nullable decimal type) there is a bug here as the Name field in the query is coming from a subselect which can be null. See the query here:
-- name: Test :manyselect
otherfield,
(selecto.namefrom one o whereone.name=5limit1) as"name"from one;
In the simplest case, if the one table has one row where .name is not 5, this query will run fine in postgres and return results, and then the results should fail to bind properly because null will be returned and attempt to scan into Name decimal.Decimal which isn't a valid value for a decimal.Decimal.
Kyle's response earlier in the thread tries to show that there is "no bug" by creating a smaller reproduce but in doing so avoids the bug altogether because the bug seems contingent on having replaced types in the config file (as I have in my playground link).
Let me know if further explanation is required but let's keep the issue opened so long as sqlc is generating structs that cannot be bound to all result sets from a given query.
Edit: Sorry, wrote the wrong struct in the above. Corrected.
Activity
kyleconroy commentedon Oct 9, 2021
I'm not able to reproduce this error. The playground link you provided is working as intended.
I created a smaller example (https://play.sqlc.dev/p/984e6f38c34bd8ef7ea26c9e246738f38fd993e90b1f105cdf89fe185cb55a48) and it's working as intended as well.
aarondl0 commentedon Oct 9, 2021
I think you may be misunderstanding the complaint.
Let me explain more clearly (I have a bit more time now). There is a subselect query happening where we're retrieving a single value from it:
If you look at the struct it created to capture the result of
Testquery in the playground it is:However it should be:
The first struct (the one sqlc generates and is in my playground link) is incorrect. This valid query cannot properly be bound to this struct for all possible return values (as the subquery can return null). Does that make it more clear?
Your example is working I agree. However I could only reproduce when using type overrides which your example does not include. Please take another look.
voluntas commentedon Jul 21, 2022
I am also having the same problem. Even if I reflect the type in sqlc.yml in the subquery results, it is not applied. Could you please check this Issue again?
jakoguta commentedon Jul 23, 2022
@WesleyMiller1998 I agree this issue configuration and generation seems to works fine; as the override is done at the database data type. However, your issue #1752 the override requested is by column name and it does have a bug. @kyleconroy I propose this issue to be closed.
aarondl0 commentedon Jul 23, 2022
@jakoguta @WesleyMiller1998 this issue is still a real issue. There's a clear reproduce here in my original playground link: https://play.sqlc.dev/p/bb47e4143c86e1b45bc659b147c4072d0464d968332d8598e36f7c2e3e531f18
Note the struct:
Until
Nameis generated as adecimal.NullDecimal(as per the config for the nullable decimal type) there is a bug here as theNamefield in the query is coming from a subselect which can benull. See the query here:In the simplest case, if the
onetable has one row where .name is not 5, this query will run fine in postgres and return results, and then the results should fail to bind properly becausenullwill be returned and attempt to scan intoName decimal.Decimalwhich isn't a valid value for adecimal.Decimal.Kyle's response earlier in the thread tries to show that there is "no bug" by creating a smaller reproduce but in doing so avoids the bug altogether because the bug seems contingent on having replaced types in the config file (as I have in my playground link).
Let me know if further explanation is required but let's keep the issue opened so long as sqlc is generating structs that cannot be bound to all result sets from a given query.
Edit: Sorry, wrote the wrong struct in the above. Corrected.
voluntas commentedon Jul 25, 2022
@aarondl0 Thank you for the very detailed way to reproduce this. I am experiencing the same problem.
vovean commentedon Feb 5, 2025
Hi! Any update on the issue?