Skip to content

Type cast issue when union null and not null value #2080

Open
@qwwwpp

Description

@qwwwpp

Version

Other

What happened?

Version 1.17.0
I am trying to list all the data in both tables with "UNION", one of the table have a NOT NULL column(created_time in the following example), and another one have a nullable column. The sqlc generated function (ListNewAndOldUsers) returns NewUser.

type NewUser struct {
	ID          int32
	CreatedTime time.Time
}

When the query returns some old_user with null created_time, it will throw unsupported Scan, storing driver.Value type <nil> into type *time.Time

Relevant log output

No response

Database schema

CREATE TABLE IF NOT EXISTS new_user(
  id int NOT NULL, 
  created_time timestamp NOT NULL
);

CREATE TABLE IF NOT EXISTS old_user(
  id int NOT NULL, 
  created_time timestamp
);

SQL queries

-- name: ListNewAndOldUsers :many
SELECT id, created_time from new_user
union
SELECT id, created_time from old_user;

Configuration

No response

Playground URL

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

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