Re: [HACKERS] identity columns - Mailing list pgsql-hackers

From Robert Haas
Subject Re: [HACKERS] identity columns
Date
Msg-id CA+TgmoYtwSgPBxY6=3C0vJYhDQj3V9Na=GMEqMzf61t51q9WOg@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] identity columns  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
Responses Re: [HACKERS] identity columns  (Peter Eisentraut <peter.eisentraut@2ndquadrant.com>)
List pgsql-hackers
On Thu, Apr 27, 2017 at 3:42 PM, Peter Eisentraut
<peter.eisentraut@2ndquadrant.com> wrote:
> On 4/27/17 10:03, Robert Haas wrote:
>>> So we could make up new syntax
>>>
>>> ALTER TABLE t1 ALTER COLUMN c1 SET GENERATED ALWAYS AS IDENTITY;
>>>
>>> and let that be set-or-add, but then the argument for staying within the
>>> SQL standard goes out the window.
>>
>> What does the SQL standard actually mandate here?  It's not clear to
>> me which parts of this syntax are mandated by the standard and which
>> we just made up.  I'm gathering (perhaps incorrectly) that you made
>> ALTER TABLE ... DROP IDENTITY as per standard, but the reverse
>> operation of setting the identity non-standard syntax.  If that's so,
>> it seems like a questionable choice.
>
> Standard syntax:
>
> 1. Add new column with identity:
>
> ALTER TABLE t1 ADD COLUMN c1 int GENERATED ALWAYS AS IDENTITY;
>
> (or equivalent for CREATE TABLE)
>
> 2. Change ALWAYS to BY DEFAULT (or vice versa) of existing column:
>
> ALTER TABLE t1 ALTER COLUMN c1 SET GENERATED BY DEFAULT;
>
> 3. Change sequence parameters of existing column:
>
> ALTER TABLE t1 ALTER COLUMN c1 SET (START 2)
>
> (the previous two can be combined)
>
> 4. Drop identity property of existing column:
>
> ALTER TABLE t1 ALTER COLUMN c1 DROP IDENTITY;
>
> (with IF EXISTS being our extension)
>
> There is no standard syntax for the inverse, that is, adding an identity
> property to an existing column.  (I have checked DB2 and Oracle.  They
> don't have anything either.  One even documents that explicitly.)
> Therefore ...
>
> Nonstandard syntax:
>
> 5. Add identity property to existing column:
>
> ALTER TABLE t1 ALTER COLUMN c1 ADD GENERATED ALWAYS AS IDENTITY;
>
> The competing proposal is that we should not have syntax #5 but that
> syntax #2 should (also) do that.
>
> My concerns about that, as previously explained, are
>
> - asymmetric idempotency behavior with DROP IDENTITY
>
> - ambiguous/inconsistent behavior when sequence options are specified in
> same command
>
> - syntax ambiguity/inconsistency with other SQL standard features
>
> The argument in favor is that syntax #5 is nonstandard.  But of course
> making #2 doing something nonstandard is also nonstandard.

OK, got it.  Given that explanation, I'm not really prepared to argue
this matter further.  That sounds basically reasonable, even if
somebody else might've chosen to do things differently.

I still think you should consider improving the psql output, though.
Vitaly's examples upthread indicate that for a serial sequence,
there's psql output showing the linkage between the table and sequence
in both directions, but not when GENERATED is used.  Can we get
something morally equivalent for the GENERATED case?

-- 
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [HACKERS] Partition-wise join for join between (declaratively)partitioned tables
Next
From: Andrew Dunstan
Date:
Subject: [HACKERS] frogmouth failures