Developer's notes

Go to Blog

GENERATED ALWAYS AS IDENTITY is a PostgreSQL construction that creates an identity column for a table and forbids to specify a value for this field manually. E.g.

CREATE TABLE users (
    id INT GENERATED ALWAYS AS IDENTITY,
    name VARCHAR NOT NULL
);

INSERT INTO users(name) VALUES ('John Smith'); -- generates id value
INSERT INTO users(id, name) VALUES (42, 'Sam Smith'); -- throws an error