Looking to create a table like the following:
CREATE TABLE newtable (
id UUID GENERATED ALWAYS AS gen_random_uuid() STORED,
org uuid NOT NULL,
name text,
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
UNIQUE(name, org)
)
But I am getting an error:
Query 1 ERROR: ERROR: syntax error at or near "gen_random_uuid"
LINE 2: id UUID GENERATED ALWAYS AS gen_random_uuid() STORED
Postgres docs here(generated columns) and here (table creation) say this should be possible:
GENERATED ALWAYS AS ( generation_expr ) STORED This clause creates the column as a generated column. The column cannot be written to, and when read the result of the specified expression will be returned.
The keyword STORED is required to signify that the column will be computed on write and will be stored on disk.
The generation expression can refer to other columns in the table, but not other generated columns. Any functions and operators used must be immutable. References to other tables are not allowed.
What am I missing? Is gen_random_uuid not a generation expression? It seems to fit all of the criteria.