Skip to content

LIMIT parameter type should be sql.NullInt32? #210

Closed
@fwojciec

Description

@fwojciec

First of all - thank you for this extremely useful tool!

Sqlc uses int32 type as parameter for LIMIT in queries, for example for this query

-- name: ListAuthors :many
SELECT * FROM authors
ORDER BY name
LIMIT $1 OFFSET $2;

sqlc will generate this set of params:

type ListAuthorsParams struct {
	Limit  int32
	Offset int32
}

According to Postgres docs it should be also possible to use NULL as the argument to LIMIT to effectively omit the LIMIT clause. This is very useful for queries where LIMIT is optional.

It's possible to work around this by passing some arbitrary large number as the parameter, but that seems like a hack.

Would it be possible to use something like sql.NullInt32 instead of int32 as the parameter for LIMIT so that it's possible to dynamically assign NULL to LIMIT in queries?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions