Skip to content

sqlc >= v1.18.0 detects a string concatenation as sql.NullBool #2734

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

Open
jamietanna opened this issue Sep 15, 2023 · 4 comments
Open

sqlc >= v1.18.0 detects a string concatenation as sql.NullBool #2734

jamietanna opened this issue Sep 15, 2023 · 4 comments

Comments

@jamietanna
Copy link

Version

1.21.0

What happened?

I've just done a few version bumps up to v1.21.0 and noticed that:

select
-- ...
db.engine || ' ' || db.engine_version as runtime

Ends up being converted to an sql.NullBool.

The upgrade diff for the generate structs can be found below:

 // Code generated by sqlc. DO NOT EDIT.
 // versions:
-//   sqlc v1.17.0
+//   sqlc v1.21.0
 // source: queries.sql
 
 package db
@@ -198,21 +198,11 @@ where
 `
 
 type RetrieveAWSAdvisoriesRow struct {
-       Arn            string
-       Name           string
-       Runtime        interface{}
-       AdvisoryType   interface{}
-       Description    interface{}
-       Arn_2          string
-       Name_2         string
-       Runtime_2      string
-       AdvisoryType_2 interface{}
-       Description_2  interface{}
-       Arn_3          string
-       Name_3         string
-       Runtime_3      interface{}
-       AdvisoryType_3 interface{}
-       Description_3  interface{}
+       Arn          string
+       Name         string
+       Runtime      sql.NullBool
+       AdvisoryType interface{}
+       Description  interface{}
 }

Previously it was an interface{} or a string, whereas now it's a sql.NullBool 🤔

I've had a look back on the Playground as far back as v1.18.0 (link) and it affects that as well as up to v1.21.0 (with #2729 applied locally)

Relevant log output

No response

Database schema

No response

SQL queries

No response

Configuration

No response

Playground URL

https://play.sqlc.dev/p/4644276ab2d6a08adc69359a99b241c23a0ce108f0a01d9bb937a81d584501ef

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

@jamietanna jamietanna added bug Something isn't working triage New issues that hasn't been reviewed labels Sep 15, 2023
@jamietanna
Copy link
Author

It looks like a workaround can be to use:

  printf('%s %s', db.engine , db.engine_version) as r,

Which then outputs:

	R       sql.NullString

@jamietanna
Copy link
Author

Any idea why it may be presenting a NullString instead of just a string?

@orisano
Copy link
Contributor

orisano commented Sep 16, 2023

In SQLite it is mistaken for a bool, but in PostgreSQL and MySQL it is also an interface{}.

@orisano
Copy link
Contributor

orisano commented Sep 16, 2023

Two problems are causing this issue.

  • sqlite is treating "||" as equivalent to "OR".
  • The compiler is treating the result of the "||" operator as any.

orisano added a commit to orisano/sqlc that referenced this issue Sep 16, 2023
close sqlc-dev#2734

Fixed sqlite engine treating "||" as OR.
MySQL does not have a concat operator, so there is no need to support it.
orisano added a commit to orisano/sqlc that referenced this issue Sep 16, 2023
close sqlc-dev#2734

Fixed sqlite engine treating "||" as OR.
MySQL does not have a concat operator, so there is no need to support it.
@kyleconroy kyleconroy added 🔧 golang 📚 sqlite 💻 linux and removed triage New issues that hasn't been reviewed labels Sep 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants