On 4/23/17, Robert Haas <robertmh...@gmail.com> wrote: > On Thu, Apr 20, 2017 at 12:05 AM, Vitaly Burovoy > <vitaly.buro...@gmail.com> wrote: >> OK. Let's go through it again. >> IDENTITY is a property of a column. There are no syntax to change any >> property of any DB object via the "ADD" syntax. >> Yes, a structure (a sequence) is created. But in fact it cannot be >> independent from the column at all (I remind you that according to the >> standard it should be unnamed sequence and there are really no way to >> do something with it but via the column's DDL). > > I agree that ADD is a little odd here, but it doesn't seem terrible.
Yes, it is not terrible, but why do we need to support an odd syntax if we can use a correct one? If we leave it as it was committed, we have to support it for years. > But why do we need it? Instead of: > > ADD GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY > SET GENERATED { ALWAYS | BY DEFAULT } > DROP IDENTITY [ IF EXISTS ] > > Why not just: > > SET GENERATED { ALWAYS | BY DEFAULT } AS IDENTITY > DROP IDENTITY [ IF EXISTS ] > > Surely the ALTER TABLE command can tell whether the column is already > GENERATED, so the first form could make it generated if it's not and > adjust the ALWAYS/BY DEFAULT property if it is. I thought exactly that way, but Peter gave an explanation[1]. I had to search a different way because no one joined to the discussion at that time. One of reasons from Peter was to make "SET GENERATED" follow the standard (i.e. raise an error). I asked whether "IF NOT EXISTS" works for him instead of "ADD GENERATED". The answer[2] was "It could be done", but "it is very difficult to implement". So I wonder why the adjustment patch is not wished for being committed. >> It is even hard to detect which sequence (since they have names) is >> owned by the column: >> >> postgres=# CREATE TABLE xxx(i int generated always as identity, j >> serial); >> CREATE TABLE >> postgres=# \d xxx* >> Table "public.xxx" >> Column | Type | Collation | Nullable | Default >> --------+---------+-----------+----------+-------------------------------- >> i | integer | | not null | generated always as identity >> j | integer | | not null | nextval('xxx_j_seq'::regclass) >> >> Sequence "public.xxx_i_seq" >> Column | Type | Value >> ------------+---------+------- >> last_value | bigint | 1 >> log_cnt | bigint | 0 >> is_called | boolean | f >> >> Sequence "public.xxx_j_seq" >> Column | Type | Value >> ------------+---------+------- >> last_value | bigint | 1 >> log_cnt | bigint | 0 >> is_called | boolean | f >> Owned by: public.xxx.j >> >> I can only guess that "public.xxx_i_seq" is owned by "public.xxx.i", >> nothing proves that. >> Whereas for regular sequence there are two evidences ("Default" and "Owned >> by"). > > This seems like a psql deficiency that should be fixed. It was a part of explanation why IDENTITY is a property and therefore "SET" should be used instead of "ADD". >> Also the created sequence cannot be deleted (only with the column) or >> left after the column is deleted. > > This does not seem like a problem. In fact I'd say that's exactly the > desirable behavior. Also it is not about a problem, it is a part of explanation. >> The "[ NOT ] EXISTS" is a common Postgres' syntax extension for >> creating/updating objects in many places. That's why I think it should >> be used instead of introducing the new "ADD" syntax which contradicts >> the users' current experience. > > As noted above, I don't understand why we need either ADD or IF NOT > EXISTS. Why can't SET just, eh, set the property to the desired > state? +1 > -- > Robert Haas > EnterpriseDB: http://www.enterprisedb.com > The Enterprise PostgreSQL Company [1] https://postgr.es/m/497c40af-bd7a-5cb3-d028-d91434639...@2ndquadrant.com [2] https://postgr.es/m/59d8e32a-14de-6f45-c2b0-bb52e4a75...@2ndquadrant.com -- Best regards, Vitaly Burovoy -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers