Closed
Description
Version
1.18.0
What happened?
We're using (and loving!) the new sqlc.embed
function, but ran into what seems to be a bug, where using embed
causes sqlc not to wrap text[]
fields in a pq.Array
function, which causes a unsupported Scan, storing driver.Value type <nil> into type *[]string
at runtime. Replacing the sqlc.embed(records)
call with a records.*
fixes the array issue, but of course means maintaining a conversion function into a struct.
This happened on a query doing some joins, but in the reproduction also happens on a single-table query.
Minimal Reproduction
In the sqlc Playground, you can see that:
- the
text_list
andint_list
fields are of typetext[]
andint[]
- first query uses a
records.*
for SELECT, and the second query usessqlc.embed(records)
- These should have essentially the same output, but in the generated
query.sql.go
file, the first query wraps the lists in apq.Array
, while the second does not. - This leads to an
unsupported Scan, storing driver.Value type <nil> into type *[]string
error at runtime.
Relevant log output
unsupported Scan, storing driver.Value type <nil> into type *[]string
Database schema
CREATE TABLE records (
id BIGSERIAL PRIMARY KEY,
text_list text[],
int_list int[]
);
SQL queries
-- name: GetRecords :many
SELECT *
FROM records;
-- name: GetRecordsWithEmbed :many
SELECT
sqlc.embed(records)
FROM
records;
Configuration
{
"version": "1",
"packages": [
{
"path": "db",
"engine": "postgresql",
"schema": "query.sql",
"queries": "query.sql"
}
]
}
Playground URL
https://play.sqlc.dev/p/bd6670f67d7952178f3aa96d510cc9f84787bbb079fe791eeaca80fa33300606
What operating system are you using?
macOS
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go