Skip to content

Cannot insert multiple values in a single INSERT statement #2331

Description

@jamietanna

Version

1.18.0

What happened?

When attempting to INSERT with multiple VALUES, we receive an error.

Relevant log output

# package db
queries.sql:1:1: INSERT has more expressions than target columns
exit status 1
internal/advisory/db/generate.go:3: running "go": exit status 1

Database schema

CREATE TABLE IF NOT EXISTS advisories (
  package_pattern TEXT NOT NULL,
  package_manager TEXT NOT NULL,
  version TEXT,
  -- lexicographically match
  version_match_strategy TEXT
    CHECK (
      version_match_strategy IN (
        "ANY",
        "EQUALS",
        "LESS_THAN",
        "LESS_EQUAL",
        "GREATER_THAN",
        "GREATER_EQUAL"
      )
    ),
  advisory_type TEXT NOT NULL
    CHECK (
      advisory_type IN (
        "DEPRECATED",
        "UNMAINTAINED",
        "SECURITY",
        "OTHER"
      )
    ),
  description TEXT NOT NULL,

  UNIQUE (package_pattern, version, version_match_strategy, advisory_type) ON CONFLICT REPLACE
);

SQL queries

-- name: InsertKnownAdvisories
INSERT INTO advisories (
  package_pattern,
  package_manager,
  version,
  version_match_strategy,
  advisory_type,
  description
) VALUES
(
  'github.com/pkg/errors',
  'gomod',
  NULL,
  NULL,
  'DEPRECATED',
  'pkg/errors is no longer necessary, as functionality exists in the Go standard library, or in better packages'
),
(
  'github.com/gorilla/*',
  'gomod',
  NULL,
  NULL,
  'UNMAINTAINED',
  'the Gorilla Toolkit was archived in 2022, and is unmaintained since'
)
;

Configuration

version: 2
sql:
  - engine: "sqlite"
    schema: "schema.sql"
    queries: "queries.sql"
    gen:
      go:
        package: db
        out: .

Playground URL

No response

What operating system are you using?

Linux, macOS

What database engines are you using?

SQLite

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Jun 16, 2023
  2. Jille commented on Jun 26, 2023

    @Jille
    Contributor

    I've pasted your queries into the sqlc playground: https://play.sqlc.dev/p/98cc6138c3af301549cc67b4c9cfa42e97ba852a537039af0828a7a13106e79b

    and reduces it to a minimal example: https://play.sqlc.dev/p/5d5ce5a2f7b24a5b106baa8d174e0496cd69270de5e12fbfb5256a12de34a607

    Additionally it complains about an Unknown node type *parser.Expr_literalContext

    Additionally, the full example outputs these warnings:

    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    2023/06/26 21:14:43 sqlite.convert: Unknown node type *parser.Expr_literalContext
    

    They seem to be caused by the NULL:
    https://play.sqlc.dev/p/98512d3690426be31a27336913b83a97bc4f3cb10c092006ff6bd4eabb448953

    but let's not discuss that in this issue

  3. added a commit that references this issue on Sep 15, 2023
    1244e5e
  4. added a commit that references this issue on Sep 25, 2023
    9c1623a
  5. added a commit that references this issue on Oct 13, 2025
    8f5ff56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtriageNew issues that hasn't been reviewed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions