sqlc icon indicating copy to clipboard operation
sqlc copied to clipboard

Limit/Offset use int32 instead of int64 with schema file vs managed db

Open pgr0ss opened this issue 2 months ago • 0 comments

Version

1.30.0

What happened?

I noticed a difference when generating queries with limit/offset between using a schema file vs a managed database connection. If the table uses an int64 primary key, then the limit and offset params should be int64. This works correctly with a managed database, but when using only a schema.sql, it generates as int32 instead.

In the config below, you can see the difference in behavior by uncommenting the managed db lines.

For simplicity, I ran sqlc for this as:

go run github.com/sqlc-dev/sqlc/cmd/[email protected] generate

And then I looked at the generated params:

type ListItemsParams struct {
	Limit  int32
	Offset int32
}

Relevant log output


Database schema

CREATE TABLE items (
    id BIGSERIAL PRIMARY KEY
);

SQL queries

-- name: ListItems :many
SELECT *
FROM items
LIMIT $1 OFFSET $2;

Configuration

version: "2"

# servers:
#   - engine: postgresql
#     uri: "postgres://user:pass@localhost:5432/db?sslmode=prefer"

sql:
  - engine: "postgresql"
    queries: "queries.sql"
    schema: "schema.sql"
    # database:
    #   managed: true
    gen:
      go:
        package: "dbsqlc"
        out: "dbsqlc"
        emit_pointers_for_null_types: true
        sql_package: "pgx/v5"

Playground URL

No response

What operating system are you using?

macOS

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

pgr0ss avatar Oct 16 '25 17:10 pgr0ss