Skip to content

inserting []byte(nil) to bytea is not treated as NULL #773

@koron

Description

@koron

this is not a bug report nor a feature request, just a question.

when I try to insert []byte(nil) as NULL like this, it was treated as 0 length bytea.
(you can see full source code at https://play.golang.org/p/6WBCgbtJKYS)

for _, b := range [][]byte{
	[]byte("hello"),
	[]byte("world"),
	nil, // this won't be stored as NULL.
} {
	_, err := db.Exec(`INSERT INTO foo1 (data) VALUES($1)`, b)
	if err != nil {
		return err
	}
}

Is this handling of []byte(nil) intentional?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions