On 12/2/26 1:33 PM, Christoph Moench-Tegeder wrote:
## Adrian Klaver ([email protected]):
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:
I always considered AS IDENTITY as a short cut for doing all ~handwaving~
that stuff with the sequence manually (just like it was/is with SERIAL).
But maybe it's not as obvious as I thought.
I would say that is correct.
The point I was trying to make comes from this part of the OP's question:
'I was curious whether or not primary key could refer to a generated
always as column.'
For the the case below it can:
GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY [ ( sequence_options ) ]
For the the other case:
GENERATED ALWAYS AS ( generation_expr ) [ STORED | VIRTUAL ]
It only works if the generated expression is STORED.
Regards,
Christoph
--
Adrian Klaver
[email protected]