Re: BUG #12991: RESTART IDENTITY is not doing anything

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Antoine Goutenoir <antoine(at)goutenoir(dot)com>
Cc: Andres Freund <andres(at)anarazel(dot)de>, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #12991: RESTART IDENTITY is not doing anything
Date: 2015-04-07 21:01:08
Message-ID: CAKFQuwaigg-sX_=3xALrba9E73sDK90RO6rbEcE9xpE_y18CQA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, Apr 7, 2015 at 12:06 PM, Antoine Goutenoir <antoine(at)goutenoir(dot)com>
wrote:

> On Tue, Apr 7, 2015 at 5:02 PM, Andres Freund <andres(at)anarazel(dot)de> wrote:
>
>> On 2015-04-07 04:07:56 +0000, antoine(at)goutenoir(dot)com wrote:
>> > Example, say Article has `id` as primary key :
>>
>> How is that table defined? Restart identity will only work if the
>> sequence is 'owned' by the id column. That happens if you either create
>> it by specifying 'serial' as the column type, or if you explicitly use
>> ALTER SEQUENCE ... OWNED BY table.col;
>>
>
> Oh, I created (actually, Doctrine created) those with :
>
> CREATE TABLE Article (id INT NOT NULL, name VARCHAR(16) NOT NULL, PRIMARY
> KEY(id));
> CREATE SEQUENCE Article_id_seq INCREMENT BY 1 MINVALUE 1 START 1;
>
> Instead of :
>
> CREATE SEQUENCE Article_id_seq INCREMENT BY 1 MINVALUE 1 START 1 OWNED BY
> Article.id;
>
>
​You seem to be missing something here because the reported Doctrine code
does nothing to change the Article.id field to use the sequence.
Typically, you would do:

CREATE TABLE Article (id serial)

And the resultant column definition would include:

[...] id integer DEFAULT ​

​nextval('sequence_name_here')​ [...]

​That particular code doesn't directly impact "Ownership"​ though, which is
strictly (I think) the mechanism by which RESTART works.

David J.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Kevin Grittner 2015-04-07 21:53:06 Re: BUG #12990: Missing pg_multixact/members files (appears to have wrapped, then truncated)
Previous Message Tomas Vondra 2015-04-07 19:50:41 Re: BUG #12992: Failure to start: too many private dirs demanded