Skip to content

Handle Postgres 'NULL' types #1097

Closed
Closed
@fresonn

Description

@fresonn

Hey!
For example, I have a schema

CREATE TYPE tag AS ENUM ('new', 'stock', 'top');

CREATE TABLE some_table (
    ...
    mainTag tag
    ...
)

You can see that the mainTag field in the table can be null.
And for the corresponding table, 'sqlc' generates me the following code

type TagType string

const (
	TagTypeNew   TagType = "new"
	TagTypeStock TagType = "stock"
	TagTypeTop     TagType = "top"
)

func (e *TagType) Scan(src interface{}) error {
	switch s := src.(type) {
	case []byte:
		*e = TagType(s)
	case string:
		*e = TagType(s)
	default:
		return fmt.Errorf("unsupported scan type for TagType: %T", src)
	}
	return nil
}

After I try to translate data from the database, I always get an error in the default case: "unsupported scan type for ...."

Question.
SQLC can track that this field can have a NULL value in the schema?

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