Skip to content

sqlc.slice(): Generate code with unused imports #3065

Closed

Description

@flrossetto

Version

1.24.0

What happened?

The code imports the unused "strings" package.

Relevant log output

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.24.0
// source: query.sql

package tutorial

import (
	"context"
	"strings"
)

const getAuthor = `-- name: GetAuthor :one
SELECT id, name, bio FROM authors
WHERE id = any($1)
`

func (q *Queries) GetAuthor(ctx context.Context, idList []int64) (Author, error) {
	row := q.db.QueryRow(ctx, getAuthor, idList)
	var i Author
	err := row.Scan(&i.ID, &i.Name, &i.Bio)
	return i, err
}

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  bio  text
);

SQL queries

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = any(sqlc.slice('id_list'));

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "tutorial"
        out: "tutorial"
        sql_package: "pgx/v5"

Playground URL

https://play.sqlc.dev/p/7f1ba3b245cc4cbdf50a7512c4a598d701d80eda56de8ef60fd26393e3ca1605

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Dec 17, 2023
  2. Jille commented on Dec 21, 2023

    @Jille
    Contributor

    I think you might be better off using:

    SELECT * FROM authors WHERE id = any(sqlc.arg('id_list')::integer[]);

    This side-steps the bug and is probably better for statement caching done by the client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions