Re: [PERFORM] Auto generate number in Postgres-9.1. - Mailing list pgsql-performance

From Andreas Karlsson
Subject Re: [PERFORM] Auto generate number in Postgres-9.1.
Date
Msg-id 84f4e415-02ef-b22b-8a3e-6d95b66b660b@proxel.se
Whole thread Raw
In response to Re: [PERFORM] Auto generate number in Postgres-9.1.  (Josh Berkus <josh@berkus.org>)
List pgsql-performance
On 03/20/2017 02:43 PM, Josh Berkus wrote:
>> If I truncate the same table and then again insert rows should start
>> with 1 in “ID” column.
>
> That's not how it works, normally.  I'd suggest adding an ON TRUNCATE
> trigger to the table.

Actually that may not be necessary as long as you make sure to use the
RESTART IDENTITY option when running TRUNCATE. I would argue that is a
cleaner solution than using triggers, if you can get away with it.

https://www.postgresql.org/docs/9.6/static/sql-truncate.html

Andreas


pgsql-performance by date:

Previous
From: Josh Berkus
Date:
Subject: Re: [PERFORM] Auto generate number in Postgres-9.1.
Next
From: John Gorman
Date:
Subject: Re: [PERFORM] Auto generate number in Postgres-9.1.