Skip to content

Mark query parameters as nullable #1155

Description

@kyleconroy

For the following query, sqlc will generate a function signature with a string for parameter $1.

CREATE TABLE users ( name TEXT NOT NULL );

-- name: ListUsers :many
SELECT *
FROM users
WHERE name = $1;
func (q *Queries) ListUsers(ctx context.Context, name string) ([]string, error) {
    // ...
}

How should we indicate that parameter $1 should be nullable?

Option 1: Add a parameter to the sqlc.arg function

CREATE TABLE users ( name TEXT NOT NULL );

-- name: ListUsers :many
SELECT *
FROM users
WHERE name = sqlc.arg('name', nullable => true);

Originally reported in #200

Activity

  1. imraan-go commented on Aug 28, 2021

    @imraan-go

    Option 1 seems to be the best way to implement this feature.

  2. mrsufgi commented on Aug 29, 2021

    @mrsufgi

    how would you go about the shorthand for @param? new syntax? no shorthand?

  3. kyleconroy commented on Aug 29, 2021

    @kyleconroy
    CollaboratorAuthor

    @mrsufgi the shorthand syntax is problematic (see #605), so for now this would only work when using sqlc.arg.

  4. removed
    triageNew issues that hasn't been reviewed
    on Sep 20, 2021
  5. kyleconroy commented on Jun 12, 2022

    @kyleconroy
    CollaboratorAuthor

    Fixed by #1536

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

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions