Re: Auto generate number in Postgres-9.1.

From: Andreas Karlsson <andreas(at)proxel(dot)se>
To: Josh Berkus <josh(at)berkus(dot)org>, Dinesh Chandra 12108 <Dinesh(dot)Chandra(at)cyient(dot)com>, "pgsql-performance-owner(at)postgresql(dot)org" <pgsql-performance-owner(at)postgresql(dot)org>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Auto generate number in Postgres-9.1.
Date: 2017-03-20 13:48:23
Message-ID: 84f4e415-02ef-b22b-8a3e-6d95b66b660b@proxel.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message John Gorman 2017-03-20 13:50:06 Re: Auto generate number in Postgres-9.1.
Previous Message Josh Berkus 2017-03-20 13:43:11 Re: Auto generate number in Postgres-9.1.