GENERATED AS IDENTITY
GENERATED AS IDENTITY is a SQL statement in the PostgreSQL Specific category. SQL standard identity column (PostgreSQL 10+). Alternative to SERIAL with more control (ALWAYS vs BY DEFAULT). The syntax is column type GENERATED [ALWAYS | BY DEFAULT] AS IDENTITY;. It returns identity column. A typical example: CREATE TABLE users ( id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY, name TEXT ); -- ALWAYS: cannot manually insert id values CREATE TABLE users ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, name TEXT ); -- BY DEFAULT: manual inserts allowed, auto-gen only when omitted A close relative is SERIAL, which postgreSQL auto-increment type. Creates an INTEGER column with a sequence. Equivalent to AUTO_INCREMENT in MySQL. A close relative is RETURNING, which postgreSQL extension that returns values from INSERT/UPDATE/DELETE statements (like OUTPUT in SQL Server). A close relative is ARRAY, which postgreSQL supports array columns and array operations. Can be multi-dimensional.