Skip to content

Invalid UUID type is generated for null column with foreign key #3671

@illiafox

Description

@illiafox

Version

1.27.0

What happened?

Generated models.go

// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0

package repository

import (
	"github.com/google/uuid"
)

type Item struct {
	ID       uuid.UUID `db:"id"`
	ParentID uuid.UUID `db:"parent_id"`
	Name     string    `db:"name"`
}

I expect sqlc to generate ParentID *uuid.UUID, because this column is nullable

Relevant log output

No response

Database schema

CREATE TABLE IF NOT EXISTS items
(
    id         UUID PRIMARY KEY           DEFAULT uuid_generate_v4(),
    parent_id  UUID REFERENCES items (id) NULL,
    name TEXT NOT NULL
);

SQL queries

-- name: CreateItem :exec
INSERT INTO items (id, parent_id, name)
VALUES (@id,
        @parent_id,
        @name);

Configuration

version: "2"
sql:
  - engine: "postgresql"
    queries: "query.sql"
    schema: "schema.sql"
    gen:
      go:
        package: "repository"
        out: "."
        sql_package: "pgx/v5"
        emit_all_enum_values: true
        emit_db_tags: true
        emit_interface: true
        emit_json_tags: true
        emit_prepared_queries: true
        emit_enum_valid_method: true
        emit_empty_slices: true
        emit_params_struct_pointers: true
        emit_result_struct_pointers: true
        emit_pointers_for_null_types: true
        json_tags_case_style: "snake"
        query_parameter_limit: 2
        overrides:
          - db_type: "uuid"
            go_type: "github.com/google/uuid.UUID"
          - db_type: "uuid"
            go_type: "github.com/google/uuid.UUID"
            nullable: true

Playground URL

https://play.sqlc.dev/p/5121c5319cdf6954e4bbfd00e098390d567401afe8cd5418ce9fb4217ac902c7

What operating system are you using?

macOS

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