Closed
Description
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