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

From Josh Berkus
Subject Re: [PERFORM] Auto generate number in Postgres-9.1.
Date
Msg-id 97da050c-395c-7205-c5e9-95e7fdf13fde@berkus.org
Whole thread Raw
In response to [PERFORM] Auto generate number in Postgres-9.1.  (Dinesh Chandra 12108 <Dinesh.Chandra@cyient.com>)
Responses Re: [PERFORM] Auto generate number in Postgres-9.1.  (Andreas Karlsson <andreas@proxel.se>)
Re: [PERFORM] Auto generate number in Postgres-9.1.  (John Gorman <jgorman@eldocomp.com>)
List pgsql-performance
Dinesh,

> I have to add one column  “ID” in postgres table which will generate
> Auto Increment
> <http://www.davidghedini.com/pg/entry/postgresql_auto_increment>ed number .
>
>
>
> Example:
>
> Suppose I have five records and if I insert 1 new record It should auto
> generate 6.

https://www.postgresql.org/docs/9.6/static/sql-createsequence.html
also SERIAL on this page:
https://www.postgresql.org/docs/9.6/static/datatype-numeric.html


>
> 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.


--
Josh Berkus
Containers & Databases Oh My!


pgsql-performance by date:

Previous
From: Dinesh Chandra 12108
Date:
Subject: [PERFORM] Auto generate number in Postgres-9.1.
Next
From: Andreas Karlsson
Date:
Subject: Re: [PERFORM] Auto generate number in Postgres-9.1.