Skip to content
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

sqlc.embed isn't wrapping text[] fields in a pq.Array #2458

Closed
will-wow opened this issue Jul 13, 2023 · 1 comment · Fixed by #2544
Closed

sqlc.embed isn't wrapping text[] fields in a pq.Array #2458

will-wow opened this issue Jul 13, 2023 · 1 comment · Fixed by #2544
Labels
bug Something isn't working triage New issues that hasn't been reviewed

Comments

@will-wow
Copy link

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 and int_list fields are of type text[] and int[]
  • first query uses a records.* for SELECT, and the second query uses sqlc.embed(records)
  • These should have essentially the same output, but in the generated query.sql.go file, the first query wraps the lists in a pq.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

@will-wow will-wow added bug Something isn't working triage New issues that hasn't been reviewed labels Jul 13, 2023
@roozbehsayadi
Copy link

We're having the same problem.

orisano added a commit to orisano/sqlc that referenced this issue Jul 30, 2023
kyleconroy pushed a commit that referenced this issue Jul 30, 2023
* fix(codegen/golang): fix sqlc.embed to work with pq.Array wrap

close #2458

* test: add endtoend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working triage New issues that hasn't been reviewed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants