Skip to content

missing argument in ORDER BY clause #4211

Open

Description

@em-ily-dev

Version

1.30.0

What happened?

The generated code for the following schema supplies only one of the two parameters in the query.

const getMainSequence = `-- name: GetMainSequence :one
SELECT ID FROM Sequence
WHERE SeriesID = ?
ORDER BY Name = ? DESC, ID
LIMIT 1
`

func (q *Queries) GetMainSequence(ctx context.Context, seriesid string) (string, error) {
	row := q.db.QueryRowContext(ctx, getMainSequence, seriesid)
	var id string
	err := row.Scan(&id)
	return id, err
}

This seems similar to #3990 and #3834.

Relevant log output

msg="missing argument with index 2"

Database schema

CREATE TABLE Sequence
(
	ID       TEXT PRIMARY KEY DEFAULT (newID()),
	Name     TEXT NOT NULL,
	SeriesID TEXT NOT NULL REFERENCES Series
)
STRICT;

SQL queries

-- name: GetMainSequence :one
SELECT ID FROM Sequence
WHERE SeriesID = ?
ORDER BY Name = ? DESC, ID
LIMIT 1;

Configuration

{
  "version": "2",
  "sql": [
    {
      "engine": "sqlite",
      "queries": "query.sql",
      "schema": "ddl",
      "gen": {
        "go": {
          "package": "schema",
          "out": "schema",
          "emit_exact_table_names": true,
          "emit_pointers_for_null_types": true,
          "rename": {
            "artworkkey": "ArtworkKey",
            "ownerid": "OwnerID",
            "sequenceid": "SequenceID",
            "seriesid": "SeriesID",
            "sortkey": "SortKey",
            "tagid": "TagID"
          }
        }
      }
    }
  ]
}

Playground URL

No response

What operating system are you using?

Linux

What database engines are you using?

SQLite

What type of code are you generating?

Go

Activity

  1. added
    bug
    on Dec 1, 2025
  2. Kyoya67 commented on Nov 15, 2026

    @Kyoya67

    I investigated this issue and confirmed that it appears to have been resolved by PR #4535.

    1. Reproduction

    I tested the exact SQL query from this issue using a minimal SQLite schema.

    sqlc v1.30.0 — Issue reproduced

    The generated code only passes one argument, despite the SQL containing two ? placeholders.

    func (q *Queries) GetMainSequence(ctx context.Context, seriesid string) (string, error) {
        row := q.db.QueryRowContext(ctx, getMainSequence, seriesid)
        var id string
        err := row.Scan(&id)
        return id, err
    }

    Current main — Issue not reproduced

    Both parameters are correctly generated and passed to QueryRowContext.

    type GetMainSequenceParams struct {
        Seriesid string
        Name     string
    }
    
    func (q *Queries) GetMainSequence(ctx context.Context, arg GetMainSequenceParams) (string, error) {
        row := q.db.QueryRowContext(ctx, getMainSequence, arg.Seriesid, arg.Name)
        var id string
        err := row.Scan(&id)
        return id, err
    }

    2. Identifying the fix with git bisect

    Since the issue was reproducible in v1.30.0 but not on main, I used git bisect to identify the commit where the behavior changed.

    I created a Bash script that:

    1. Builds sqlc from the currently checked-out commit.
    2. Generates Go code using the reproduction query.
    3. Checks whether both SQL parameters are passed to QueryRowContext.
    4. Returns an exit code indicating whether the issue is reproduced.

    I then ran git bisect run to automatically test commits between v1.30.0 and main, using reversed good/bad classifications to locate the fix.

    First commit where the issue no longer reproduces:

    This PR replaces the SQLite ANTLR parser with meyer. The commit description also mentions that the previous parser incorrectly handled ORDER BY expressions.

    The bisect results confirm that the reported behavior changes at this commit, although I haven't isolated the exact parser change responsible.

    3. Conclusion

    Based on the reproduction results and git bisect, this issue appears to have been resolved by #4535.

    Could a maintainer confirm whether this issue can be closed?

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions