sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

`sqlc.arg` (and it's shorthand `@`) not working for `LIMIT` and `OFFSET`

Open 733amir opened this issue 10 months ago • 2 comments

Version

1.28.0

What happened?

The sqlc.arg or @ is not working for LIMIT and OFFSET.

Relevant log output

sqlc generate failed.
# package 
query.sql:23:9: syntax error at or near "limit"

Database schema

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

SQL queries

-- name: PaginatedShorthand :many
select * from authors
limit @limit offset @offset;

-- name: Paginated :many
select * from authors
limit sqlc.arg(limit) offset sqlc.arg(offset);

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db"
      }
    }
  }]
}

Playground URL

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

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

733amir avatar Feb 13 '25 09:02 733amir

I am having this exact same issue - cannot seem to combine the offset and limit clauses.

FA5I avatar Mar 18 '25 14:03 FA5I

I was able to work around this by choosing non-keyword names:

LIMIT sqlc.narg(aaa) OFFSET sqlc.arg(bbb);

seanlafferty-ibm avatar Jun 17 '25 01:06 seanlafferty-ibm