| From: | Josh Berkus <josh(at)berkus(dot)org> |
|---|---|
| To: | 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:43:11 |
| Message-ID: | 97da050c-395c-7205-c5e9-95e7fdf13fde@berkus.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | 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!
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andreas Karlsson | 2017-03-20 13:48:23 | Re: Auto generate number in Postgres-9.1. |
| Previous Message | Dinesh Chandra 12108 | 2017-03-20 13:38:40 | Auto generate number in Postgres-9.1. |