Skip to content

Batch queries referencing only schema types missing imports for pgtype and database/sql #1792

Closed
@chrisyxlee

Description

@chrisyxlee

Version

Other

What happened?

Version: 1.15.0

Similar to #1682

batch.go fails to import "github.com/jackc/pgtype" and "database/sql" for batch queries statements when only the schema references the type.

The imports are correct when one of the parameters for the query use that specific type (e.g. WHERE bio = $1::JSONB will import the correct packages).

Relevant log output

n/a

Database schema

-- Example queries for sqlc
CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  JSONB,
  published BOOLEAN
);

SQL queries

-- name: GetAuthor :batchone
SELECT bio, published FROM authors
WHERE id = $1
LIMIT 1;

Configuration

{
  "version": "1",
  "packages": [
    {
      "path": "db",
      "engine": "postgresql",
      "schema": "query.sql",
      "queries": "query.sql",
      "sql_package": "pgx/v4"
    }
  ]
}

Playground URL

https://play.sqlc.dev/p/bc8d330bd6e53ca6ad3cd34b15d184c4a6a99e2a19b205cbd08cb754b543ca16

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions