Skip to content

Nullable ENUM Columns use NullEnumType instead of pointer #4052

@stampflit

Description

@stampflit

Version

1.29.0

What happened?

With emit_pointers_for_null_types for pgx/v5 we can let sqlc generate query functions that use *type instead of NullType. This works for table types, but it doesn't work for enums (It also doesn't automatically work for pointer versions overridden types but that's possibly a separate issue).

To clarify: Here is the relevant excerpt of what gets generated for the example below:

type SearchFoodParams struct {
    Food     string
    FoodType NullFoodType
}

And I want

type SearchFoodParams struct {
    Food     string
    FoodType *FoodType
}

I'm not sure whether this should be a bug or a feature request. I would expect that emit_pointers_for_null_types also works for enums, so I filed it as a feature request. I'll also submit a PR that solves this issue in the next hour.

Relevant log output

Database schema

CREATE TYPE food_type AS ENUM ('sandwhich', 'salad', 'soup');

CREATE TABLE foods (
  id BIGSERIAL PRIMARY KEY,
  food text NOT NULL,
  food_type food_type -- NULL if food can't be classified.  That should ofc never happen
);

SQL queries

-- name: SearchFood :many
SELECT * FROM foods
WHERE food LIKE $1
AND food_type = $2;

Configuration

{
  "version": "2",
  "sql": [{
    "schema": "schema.sql",
    "queries": "query.sql",
    "engine": "postgresql",
    "gen": {
      "go": {
        "out": "db",
        "sql_package": "pgx/v5",
        "emit_pointers_for_null_types": true
      }
    }
  }]
}

Playground URL

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

What operating system are you using?

No response

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