Help us shape the future of Go! Take the 2026 Go Developer Survey

sequence

package
v0.26.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 25, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

PostgreSQL native reservations

PostgreSQL 10+ native catalogs resolve SERIAL, GENERATED BY DEFAULT/ALWAYS identity, direct nextval defaults (including unowned sequences), and an explicit mapped sequence. The server resolves identifiers and search_path. Non-integer columns, missing generators, ambiguous/transformed defaults without an explicit authority, cycling sequences and out-of-column-range values have shape-specific diagnostics. No source schema or trigger is changed.

insert.Service.ReserveSequence returns sink.Reservation.Values: actual values returned by nextval, in returned order. Backend caches and concurrent calls may produce [2,3,7], descending values, or values lower than an earlier reservation. No arithmetic range or monotonic last-value inference is valid for this API. The old scalar NextSequence API diagnoses this distinction before consuming values. Native insert assignment consumes the same exact-value owner.

nextval values are not reclaimed by rollback. Cancellation/exhaustion can consume values without returning a successful batch; records are not assigned partial batches. No MAX, setval, sequence restart, allocator table, source INSERT or extra caller connection is used. A supplied transaction remains caller-owned; normal PostgreSQL statement-error transaction-abort semantics still apply.

Native PostgreSQL inserts use OVERRIDING SYSTEM VALUE when materializing mapped identity values, allowing preallocated values for GENERATED ALWAYS columns. The clause is ignored by PostgreSQL for columns where it is inapplicable. RETURNING rows are consumed directly and their errors are preserved.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock added in v0.26.1

type Lock struct{}

Lock acknowledges native nextval ownership: no allocator table, source DML, sequence restart, advisory lock or extra connection is required.

func (*Lock) CanUse added in v0.26.1

func (*Lock) CanUse(...interface{}) bool

func (*Lock) Handle added in v0.26.1

func (*Lock) Handle(ctx context.Context, _ *sql.DB, _ interface{}, _ ...interface{}) (bool, error)

type Metadata added in v0.26.1

type Metadata struct{}

Metadata resolves identity/serial/default and explicit sequence authorities from PostgreSQL catalogs. Names and search_path are interpreted by PostgreSQL.

func (*Metadata) CanUse added in v0.26.1

func (*Metadata) CanUse(opts ...interface{}) bool

func (*Metadata) Handle added in v0.26.1

func (m *Metadata) Handle(ctx context.Context, db *sql.DB, target interface{}, opts ...interface{}) (bool, error)

type Next

type Next struct{}

Next represents struct used to setting new autoincrement value using insert inside new transaction finished by rollback

func (*Next) CanUse

func (n *Next) CanUse(iopts ...interface{}) bool

CanUse returns true if Handle function can be executed

func (*Next) Handle

func (n *Next) Handle(ctx context.Context, db *sql.DB, target interface{}, iopts ...interface{}) (doNext bool, err error)

Handle sets new autoincrement value by inserting row using new transaction finished by rollback, uses locking

type RangeError added in v0.26.1

type RangeError struct{}

RangeError rejects the old scalar range API before consuming sequence values.

func (*RangeError) CanUse added in v0.26.1

func (*RangeError) CanUse(...interface{}) bool

func (*RangeError) Handle added in v0.26.1

func (*RangeError) Handle(context.Context, *sql.DB, interface{}, ...interface{}) (bool, error)

type Reserve added in v0.26.1

type Reserve struct{}

func (*Reserve) CanUse added in v0.26.1

func (*Reserve) CanUse(...interface{}) bool

func (*Reserve) Handle added in v0.26.1

func (*Reserve) Handle(ctx context.Context, db *sql.DB, target interface{}, opts ...interface{}) (bool, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL