Re: [PATCHES] TRUNCATE TABLE with IDENTITY - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [PATCHES] TRUNCATE TABLE with IDENTITY
Date
Msg-id 3919.1210981275@sss.pgh.pa.us
Whole thread Raw
In response to Re: TRUNCATE TABLE with IDENTITY  (Zoltan Boszormenyi <zb@cybertec.at>)
Responses Re: [PATCHES] TRUNCATE TABLE with IDENTITY  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: [PATCHES] TRUNCATE TABLE with IDENTITY  (Neil Conway <neilc@samurai.com>)
List pgsql-hackers
Zoltan Boszormenyi <zb@cybertec.at> writes:
>> Attached patch implements the extension found in the current SQL200n draft,
>> implementing stored start value and supporting ALTER SEQUENCE seq RESTART;

> Updated patch implements TRUNCATE ... RESTART IDENTITY
> which restarts all owned sequences for the truncated table(s).

Applied with corrections.  Most notably, since ALTER SEQUENCE RESTART
is nontransactional like most other ALTER SEQUENCE operations, I
rearranged things to try to ensure that foreseeable failures like
deadlock and lack of permissions would be detected before TRUNCATE
starts to issue any RESTART commands.

One interesting point here is that the patch as submitted allowed
ALTER SEQUENCE MINVALUE/MAXVALUE to be used to set a sequence range
that the original START value was outside of.  This would result in
a failure at ALTER SEQUENCE RESTART.  Since, as stated above, we
really don't want that happening during TRUNCATE, I adjusted the
patch to make such an ALTER SEQUENCE fail.  This is at least potentially
an incompatible change: command sequences that used to be legal could
now fail.  I doubt it's very likely to bite anyone in practice, though.

            regards, tom lane

pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: missing $PostgreSQL:$
Next
From: Tom Lane
Date:
Subject: Re: [PATCHES] TRUNCATE TABLE with IDENTITY