pub const IDENTITY: ColumnMarker;Expand description
Creates a GENERATED ... AS IDENTITY column.
§Syntax
identityoridentity(always):GENERATED ALWAYS. The database rejects explicit values unless the insert saysOVERRIDING SYSTEM VALUE, so the insert model has no setter for the column.identity(by_default):GENERATED BY DEFAULT. An explicit value wins.- Sequence options may follow the mode:
start,increment,min_value,max_value,cache,cycle, as inidentity(always, start = 100, cycle).
§Examples
// GENERATED ALWAYS AS IDENTITY - strictest mode
#[column(identity(always), primary)]
id: i64,
// GENERATED BY DEFAULT AS IDENTITY - allows override
#[column(identity(by_default), primary)]
id: i64,§Technical Details
PostgreSQL’s identity columns are SQL-standard compliant, unlike SERIAL.
Use ALWAYS for auto-generated IDs, BY DEFAULT when you need to occasionally set values.
See: https://www.postgresql.org/docs/current/ddl-identity-columns.html