Skip to content

sqlc.Narg does not work with enums #1683

Closed
@Emyrk

Description

@Emyrk

Version

1.14.0

What happened?

sqlc.narg is a great addition. Unfortunately, it does not seem to work for enum types. I would really like to be able to use nullable enums, as empty strings are invalid enums and throw an error.

In the example provided, it would be great if the method definition used *Colors to make it nullable:

func (q *Queries) GetBoxes(ctx context.Context, color *Colors) ([]Box, error) {

The actual method does not accept a nullable argument.

func (q *Queries) GetBoxes(ctx context.Context, color Colors) ([]Box, error) {

Relevant log output

No response

Database schema

CREATE TYPE colors AS ENUM (
    'red',
    'blue',
    'green'
);

-- Example queries for sqlc
CREATE TABLE boxs (
  id   BIGSERIAL PRIMARY KEY,
  name text      NOT NULL,
  color colors
);

SQL queries

-- name: GetBoxes :many
SELECT * FROM boxs
WHERE 
CASE
	WHEN sqlc.narg('color') :: colors != null THEN
		color = sqlc.narg('color')
	ELSE true
END;

Configuration

No response

Playground URL

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

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions