On 12/2/26 10:40 AM, Christoph Moench-Tegeder wrote:
## Bruno Wolff III ([email protected]):
I was curious whether or not primary key could refer to a generated
always as column. I didn't find an answer under create table or
section 5.4. Maybe I missed it. It was easy enough to test and seems
to work like I guessed.
There's a GENERATED BY DEFAULT in the Examples section of CREATE TABLE:
https://www.postgresql.org/docs/current/sql-createtable.html
Second CREATE TABLE in the first example block.
Is GENERATED ALWAYS so different that it needs extra documentation?
I would say yes. The example refers to an IDENTITY column where DEFAULT
is one of two options, the other being ALWAYS. The whole command is:
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
It is an SQL standard replacement for the serial type:
https://www.postgresql.org/docs/current/ddl-identity-columns.html
What the OP is referring to is:
GENERATED ALWAYS AS ( generation_expr ) [ STORED | VIRTUAL ] |
That is different beast altogether if for no other reason then you have
the STORED or VIRUAL options. There is also the matter of the
generation_expr which you have some degree of control over.
Regards,
Christoph
--
Adrian Klaver
[email protected]