Skip to content

Enums in joins are not treated as nullable #1157

Closed

Description

@johanbrandhorst

Version

1.9.0

What happened?

Support for nullable columns in joins were added in v1.9.0. Unfortunately, it appears this doesn't extend to the auto-generated enum types. As can be seen in the generated Go types, the ListBooksRow contains an sql.NullString, but the enum type is not similarly nullable.

There's a bit of a design discussion to be had around what the best way to handle this is, since enums use a custom type. Perhaps a pointer would be enough, so that it could be null?

Related to #374

Relevant log output

No response

Database schema

CREATE TABLE authors (
  id   BIGSERIAL PRIMARY KEY,
  name TEXT      NOT NULL
);

CREATE TYPE book_type AS ENUM ('hardback', 'softback', 'ebook');

CREATE TABLE books (
  id        BIGSERIAL PRIMARY KEY,
  title     TEXT      NOT NULL,
  book_type book_type NOT NULL,
  author_id BIGINT    NULL        REFERENCES authors(id)
);

SQL queries

-- name: ListBooks :many
SELECT authors.name, books.title, books.book_type FROM authors
LEFT JOIN books ON authors.id = books.author_id;

Configuration

version: 1
packages:
  - path: "tutorial"
    name: "tutorial"
    engine: "postgresql"
    schema: "schema.sql"
    queries: "query.sql"

Playground URL

https://play.sqlc.dev/p/086e386e94012b813b228429fc8067716c2b68e66db27de20699daafdb9d12b9

What operating system are you using?

Linux

What database engines are you using?

PostgreSQL

What type of code are you generating?

Go

Activity

  1. added
    bugSomething isn't working
    triageNew issues that hasn't been reviewed
    on Aug 29, 2021
  2. kyleconroy commented on Aug 29, 2021

    @kyleconroy
    Collaborator

    Just wanted to thank you for writing up such a complete bug report. The custom Enum types currently don't support NULL. Once they do (tracking in #1097) the existing JOIN support should "just work".

  3. added this to the v1.10.0 milestone on Aug 29, 2021
  4. modified the milestones: v1.10.0, v1.11.0 on Sep 5, 2021
  5. removed this from the v1.11.0 milestone on Jan 31, 2022
  6. sbres commented on Mar 14, 2022

    @sbres
    Contributor

    I've created the PR #1485 that should solve this problem.

  7. Jille commented on May 2, 2022

    @Jille
    Contributor
  8. SnoozeThis commented on May 2, 2022

    @SnoozeThis
  9. sgrishanin commented on May 11, 2023

    @sgrishanin

    @kyleconroy hi, is there any traction on this issue? The aforementioned PR #1485 does not fix this particular issue (not sure what it does honestly), when scanning non-nullable enum that's still null as a result of join

  10. sbres commented on May 11, 2023

    @sbres
    Contributor

    I've tested the query in the issue on the playground and it is working properly.
    Could you please share what is the model and the query you find problems with?

  11. johanbrandhorst commented on May 11, 2023

    @johanbrandhorst
    ContributorAuthor

    The original issue does indeed seem to be fixed, thanks!

  12. SnoozeThis commented on Sep 22, 2023

    @SnoozeThis

    Resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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