Skip to content

proposal: database/sql: sql.IsNull #34593

Closed
@qaisjp

Description

@qaisjp

An addition to database/sql to quickly tell you whether one of the NullX types are in fact, "null".

It would be the addition of essentially this:

// IsNull will return true if the value given is a "null type"
//  (NullBool, NullString, etc) that is marked "invalid".
//
// Always returns false otherwise.
func IsNull(val interface{}) (invalid bool) {
	switch v := val.(type) {
	case sql.NullBool:
		invalid = !v.Valid
	case sql.NullFloat64:
		invalid = !v.Valid
	case sql.NullInt32:
		invalid = !v.Valid
	case sql.NullInt64:
		invalid = !v.Valid
	case sql.NullString:
		invalid = !v.Valid
	case sql.NullTime:
		invalid = !v.Valid
	}
	return
}

Am happy to send PR, just wanted to quickly get feedback on whether this would be fine? Or should I have used the golang-dev mailing list instead?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions