pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #12991: RESTART IDENTITY is not doing anything
4+ messages / 4 participants
[nested] [flat]
* BUG #12991: RESTART IDENTITY is not doing anything
@ 2015-04-07 04:07 antoine@goutenoir.com
2015-04-07 15:02 ` Re: BUG #12991: RESTART IDENTITY is not doing anything Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 4+ messages in thread
From: antoine@goutenoir.com @ 2015-04-07 04:07 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 12991
Logged by: Goutte
Email address: antoine@goutenoir.com
PostgreSQL version: 9.3.6
Operating system: Linux 3.13.0-45-generic x86_64 GNU/Linux
Description:
The bug is pretty straightforward, the doc is crystal clear about the role
of RESTART IDENTITY, and this is not listed is the known bugs.
For my test suite, I have to restart the identity sequences while
truncating.
I need the TRUNCATE to CASCADE too, but I don't know if it is meaningful.
Example, say Article has `id` as primary key :
TRUNCATE TABLE Article RESTART IDENTITY CASCADE;
On the next insertion, the sequence will continue from where it was before
instead of being resetted. The table is successfully truncated, though.
I solve it by doing, right after :
ALTER SEQUENCE Article_id_seq RESTART WITH 1;
This works and restarts the sequence.
---
I observe this behavior (or non-behavior in this case) on the cli using the
`psql` binary, and programmatically in PHP, so I'm sure this is not my
connector acting up.
---
Please note that I'm a pgSQL absolute noob (first day), and I'm using it
because of the awesome `earthdistances` extension.
Maybe I missed something obvious !
Good day to you,
Antoine
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #12991: RESTART IDENTITY is not doing anything
2015-04-07 04:07 BUG #12991: RESTART IDENTITY is not doing anything antoine@goutenoir.com
@ 2015-04-07 15:02 ` Andres Freund <andres@anarazel.de>
2015-04-07 19:06 ` Re: BUG #12991: RESTART IDENTITY is not doing anything Antoine Goutenoir <antoine@goutenoir.com>
0 siblings, 1 reply; 4+ messages in thread
From: Andres Freund @ 2015-04-07 15:02 UTC (permalink / raw)
To: antoine@goutenoir.com; +Cc: pgsql-bugs
On 2015-04-07 04:07:56 +0000, antoine@goutenoir.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;
Greetings,
Andres Freund
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #12991: RESTART IDENTITY is not doing anything
2015-04-07 04:07 BUG #12991: RESTART IDENTITY is not doing anything antoine@goutenoir.com
2015-04-07 15:02 ` Re: BUG #12991: RESTART IDENTITY is not doing anything Andres Freund <andres@anarazel.de>
@ 2015-04-07 19:06 ` Antoine Goutenoir <antoine@goutenoir.com>
2015-04-07 21:01 ` Re: BUG #12991: RESTART IDENTITY is not doing anything David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 1 reply; 4+ messages in thread
From: Antoine Goutenoir @ 2015-04-07 19:06 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: pgsql-bugs
On Tue, Apr 7, 2015 at 5:02 PM, Andres Freund <andres@anarazel.de> wrote:
> On 2015-04-07 04:07:56 +0000, antoine@goutenoir.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;
---
I did not knew about "ownership" of sequences, because the id incremented
so I thought the system knew what field to alter through the sequence name.
Thanks for the tip, I'll fork Doctrine to add it if there's no BC break
ripple effect resulting from the change.
Sorry about the bother,
Antoine
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: BUG #12991: RESTART IDENTITY is not doing anything
2015-04-07 04:07 BUG #12991: RESTART IDENTITY is not doing anything antoine@goutenoir.com
2015-04-07 15:02 ` Re: BUG #12991: RESTART IDENTITY is not doing anything Andres Freund <andres@anarazel.de>
2015-04-07 19:06 ` Re: BUG #12991: RESTART IDENTITY is not doing anything Antoine Goutenoir <antoine@goutenoir.com>
@ 2015-04-07 21:01 ` David G. Johnston <david.g.johnston@gmail.com>
0 siblings, 0 replies; 4+ messages in thread
From: David G. Johnston @ 2015-04-07 21:01 UTC (permalink / raw)
To: Antoine Goutenoir <antoine@goutenoir.com>; +Cc: Andres Freund <andres@anarazel.de>; pgsql-bugs
On Tue, Apr 7, 2015 at 12:06 PM, Antoine Goutenoir <antoine@goutenoir.com>
wrote:
> On Tue, Apr 7, 2015 at 5:02 PM, Andres Freund <andres@anarazel.de> wrote:
>
>> On 2015-04-07 04:07:56 +0000, antoine@goutenoir.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.
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2015-04-07 21:01 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2015-04-07 04:07 BUG #12991: RESTART IDENTITY is not doing anything antoine@goutenoir.com
2015-04-07 15:02 ` Andres Freund <andres@anarazel.de>
2015-04-07 19:06 ` Antoine Goutenoir <antoine@goutenoir.com>
2015-04-07 21:01 ` David G. Johnston <david.g.johnston@gmail.com>
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