pg.ddx.io pgsql-hackers@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Vitaly Burovoy <vitaly.burovoy@gmail.com>
Cc: pgsql-hackers <pgsql-hackers@postgresql.org>
Subject: Re: identity columns
Date: Thu, 27 Apr 2017 15:42:02 -0400
Message-ID: <0334bd69-ab72-384a-684d-4595d761beea@2ndquadrant.com> (raw )
In-Reply-To: <CA+Tgmoazvm1zk9F_8dWK7g2B=UUEYmogVfvGG83v_umOoCVuAA@mail.gmail.com >
References: <6adbacbf-73bc-dd1a-2033-63409180fd18@2ndquadrant.com >
<CAKOSWNmRm0ydv1Yp8OzZ_GPh6Kfyhk+o-fxRb6onGfp433afFA@mail.gmail.com >
<06a416db-e35b-36d1-7e2f-0affdee24745@2ndquadrant.com >
<CAKOSWN=U0wfqjPuUbSEMAn_dcP7QnD_U0KskYf7OVhkVqs8CXA@mail.gmail.com >
<4b1d703f-818f-00bf-4169-3279af377f3d@2ndquadrant.com >
<CAKOSWNnxgYCVoNbmr2reMvwzQzyzgXMZn8F5JQhvkdFs73ae2g@mail.gmail.com >
<59d8e32a-14de-6f45-c2b0-bb52e4a7522d@2ndquadrant.com >
<CAKOSWNnLfPJE4b0_onw42QD64AzC7UESHDqK8sP2PAYERktOXQ@mail.gmail.com >
<21ab7425-ae33-b0af-4177-f2ba88acd93a@2ndquadrant.com >
<CAKOSWN=hUQWwyCJS8a3gTTUkvMkeg2iwSCCs=df0OYxJ_6H0kA@mail.gmail.com >
<7e8fafb2-1949-fd97-cb57-fb1a3fe0ed6e@2ndquadrant.com >
<CAKOSWNkWyO7WfvANNeL6bRGt2PKLLqWBJVnY4CcgdJF2b+kL7Q@mail.gmail.com >
<CA+TgmobTuLCZf8qOpGsv+ZyUguHCZk=80xE-PEreUhvydtYGJg@mail.gmail.com >
<83f5d264-6d4a-01e0-a496-fcca7933c18b@2ndquadrant.com >
<CA+Tgmoazvm1zk9F_8dWK7g2B=UUEYmogVfvGG83v_umOoCVuAA@mail.gmail.com >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
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.
--
Peter Eisentraut http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers
view thread (55+ messages) latest in thread
Message-ID: <0334bd69-ab72-384a-684d-4595d761beea@2ndquadrant.com>
Permalink: ../0334bd69-ab72-384a-684d-4595d761beea@2ndquadrant.com/
Also on: postgresql.org/message-id/0334bd69-ab72-384a-684d-4595d761beea@2ndquadrant.com
copy link · copy postgr.es
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: peter.eisentraut@2ndquadrant.com, robertmhaas@gmail.com, vitaly.burovoy@gmail.com
Subject: Re: identity columns
In-Reply-To: <0334bd69-ab72-384a-684d-4595d761beea@2ndquadrant.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox