We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
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
CREATE TABLE foo (bar TEXT[])
Generates
type Foo struct { Bar []string }
Which fails to scan if bar = NULL. Instead, maybe it should be:
bar = NULL
type Foo struct { Bar pq.StringArray }
which handles NULL.
NULL
The text was updated successfully, but these errors were encountered:
Which fails to scan if bar = NULL.
This actually isn't true. If bar is NULL, Scan will return an empty slice.
bar
CREATE TABLE foo ( id text, tags text[] ); INSERT INFO foo (id, tags) VALUES ('foo-array', NULL); -- name: ListFoo :many SELECT * FROM foo;
Calling ListFoo will succeed and return a single row with an empty slice and null ID.
ListFoo
rows, err := q.ListFoo(ctx) log.Println(rows) $ 2019/12/16 13:51:41 [{{foo-array true} []}]
However, if the array contains a null item, the Scan will fail.
playground=# insert into foo (id, tags) values ('foo-array', array[NULL]); INSERT 0 1 playground=# \q $ ./sqlc-playground 2019/12/16 13:54:07 [] 2019/12/16 13:54:07 sql: Scan error on column index 1, name "tags": pq: parsing array element index 0: cannot convert nil to string
I've opened #185 to track the issue with NULL array elements.
Sorry, something went wrong.
You're right, I was mistaken here. My issue was related to some old sqlx code that the sqlc code was interacting with that had the wrong types.
Switching it to sqlc revealed the type issue and fixed my problem.
No branches or pull requests
Uh oh!
There was an error while loading. Please reload this page.
Generates
Which fails to scan if
bar = NULL
. Instead, maybe it should be:which handles
NULL
.The text was updated successfully, but these errors were encountered: