package zeronull
import "github.com/jackc/pgx/v5/pgtype/zeronull"
Package zeronull contains types that automatically convert between database NULLs and Go zero values.
Sometimes the distinction between a zero value and a NULL value is not useful at the application level. For example, in PostgreSQL an empty string may be stored as NULL. There is usually no application level distinction between an empty string and a NULL string. Package zeronull implements types that seamlessly convert between PostgreSQL NULL and the zero value.
It is recommended to convert types at usage time rather than instantiate these types directly. In the example below, middlename would be stored as a NULL.
firstname := "John" middlename := "" lastname := "Smith" _, err := conn.Exec( ctx, "insert into people(firstname, middlename, lastname) values($1, $2, $3)", zeronull.Text(firstname), zeronull.Text(middlename), zeronull.Text(lastname), )
Index ¶
- func Register(m *pgtype.Map)
- type Float8
- func (f Float8) Float64Value() (pgtype.Float8, error)
- func (f *Float8) Scan(src any) error
- func (f *Float8) ScanFloat64(n pgtype.Float8) error
- func (Float8) SkipUnderlyingTypePlan()
- func (f Float8) Value() (driver.Value, error)
- type Int2
- func (src Int2) Int64Value() (pgtype.Int8, error)
- func (dst *Int2) Scan(src any) error
- func (dst *Int2) ScanInt64(n pgtype.Int8) error
- func (Int2) SkipUnderlyingTypePlan()
- func (src Int2) Value() (driver.Value, error)
- type Int4
- func (src Int4) Int64Value() (pgtype.Int8, error)
- func (dst *Int4) Scan(src any) error
- func (dst *Int4) ScanInt64(n pgtype.Int8) error
- func (Int4) SkipUnderlyingTypePlan()
- func (src Int4) Value() (driver.Value, error)
- type Int8
- func (src Int8) Int64Value() (pgtype.Int8, error)
- func (dst *Int8) Scan(src any) error
- func (dst *Int8) ScanInt64(n pgtype.Int8) error
- func (Int8) SkipUnderlyingTypePlan()
- func (src Int8) Value() (driver.Value, error)
- type Text
- func (dst *Text) Scan(src any) error
- func (dst *Text) ScanText(v pgtype.Text) error
- func (Text) SkipUnderlyingTypePlan()
- func (src Text) Value() (driver.Value, error)
- type Timestamp
- func (ts *Timestamp) Scan(src any) error
- func (ts *Timestamp) ScanTimestamp(v pgtype.Timestamp) error
- func (Timestamp) SkipUnderlyingTypePlan()
- func (ts Timestamp) TimestampValue() (pgtype.Timestamp, error)
- func (ts Timestamp) Value() (driver.Value, error)
- type Timestamptz
- func (ts *Timestamptz) Scan(src any) error
- func (ts *Timestamptz) ScanTimestamptz(v pgtype.Timestamptz) error
- func (Timestamptz) SkipUnderlyingTypePlan()
- func (ts Timestamptz) TimestamptzValue() (pgtype.Timestamptz, error)
- func (ts Timestamptz) Value() (driver.Value, error)
- type UUID
Functions ¶
func Register ¶
Register registers the zeronull types so they can be used in query exec modes that do not know the server OIDs.
Types ¶
type Float8 ¶
type Float8 float64
func (Float8) Float64Value ¶
Float64Value implements the pgtype.Float64Valuer interface.
func (*Float8) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*Float8) ScanFloat64 ¶
ScanFloat64 implements the pgtype.Float64Scanner interface.
func (Float8) SkipUnderlyingTypePlan ¶
func (Float8) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Float8) Value ¶
Value implements the database/sql/driver.Valuer interface.
type Int2 ¶
type Int2 int16
func (Int2) Int64Value ¶
Int64Value implements the pgtype.Int64Valuer interface.
func (*Int2) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*Int2) ScanInt64 ¶
ScanInt64 implements the pgtype.Int64Scanner interface.
func (Int2) SkipUnderlyingTypePlan ¶
func (Int2) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Int2) Value ¶
Value implements the database/sql/driver.Valuer interface.
type Int4 ¶
type Int4 int32
func (Int4) Int64Value ¶
Int64Value implements the pgtype.Int64Valuer interface.
func (*Int4) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*Int4) ScanInt64 ¶
ScanInt64 implements the pgtype.Int64Scanner interface.
func (Int4) SkipUnderlyingTypePlan ¶
func (Int4) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Int4) Value ¶
Value implements the database/sql/driver.Valuer interface.
type Int8 ¶
type Int8 int64
func (Int8) Int64Value ¶
Int64Value implements the pgtype.Int64Valuer interface.
func (*Int8) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*Int8) ScanInt64 ¶
ScanInt64 implements the pgtype.Int64Scanner interface.
func (Int8) SkipUnderlyingTypePlan ¶
func (Int8) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Int8) Value ¶
Value implements the database/sql/driver.Valuer interface.
type Text ¶
type Text string
func (*Text) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*Text) ScanText ¶
ScanText implements the pgtype.TextScanner interface.
func (Text) SkipUnderlyingTypePlan ¶
func (Text) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Text) Value ¶
Value implements the database/sql/driver.Valuer interface.
type Timestamp ¶
func (*Timestamp) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*Timestamp) ScanTimestamp ¶
ScanTimestamp implements the pgtype.TimestampScanner interface.
func (Timestamp) SkipUnderlyingTypePlan ¶
func (Timestamp) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Timestamp) TimestampValue ¶
TimestampValue implements the pgtype.TimestampValuer interface.
func (Timestamp) Value ¶
Value implements the database/sql/driver.Valuer interface.
type Timestamptz ¶
func (*Timestamptz) Scan ¶
func (ts *Timestamptz) Scan(src any) error
Scan implements the database/sql.Scanner interface.
func (*Timestamptz) ScanTimestamptz ¶
func (ts *Timestamptz) ScanTimestamptz(v pgtype.Timestamptz) error
ScanTimestamptz implements the pgtype.TimestamptzScanner interface.
func (Timestamptz) SkipUnderlyingTypePlan ¶
func (Timestamptz) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (Timestamptz) TimestamptzValue ¶
func (ts Timestamptz) TimestamptzValue() (pgtype.Timestamptz, error)
TimestamptzValue implements the pgtype.TimestamptzValuer interface.
func (Timestamptz) Value ¶
func (ts Timestamptz) Value() (driver.Value, error)
Value implements the database/sql/driver.Valuer interface.
type UUID ¶
type UUID [16]byte
func (*UUID) Scan ¶
Scan implements the database/sql.Scanner interface.
func (*UUID) ScanUUID ¶
ScanUUID implements the pgtype.UUIDScanner interface.
func (UUID) SkipUnderlyingTypePlan ¶
func (UUID) SkipUnderlyingTypePlan()
SkipUnderlyingTypePlan implements the pgtype.SkipUnderlyingTypePlanner interface.
func (UUID) UUIDValue ¶
UUIDValue implements the pgtype.UUIDValuer interface.
func (UUID) Value ¶
Value implements the database/sql/driver.Valuer interface.
Source Files ¶
doc.go float8.go int.go text.go timestamp.go timestamptz.go uuid.go zeronull.go
- Version
- v5.9.2 (latest)
- Published
- Apr 19, 2026
- Platform
- js/wasm
- Imports
- 5 packages
- Last checked
- 2 hours ago –
Tools for package owners.