Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpy0j-0007pL-Jp for pgsql-performance@arkaria.postgresql.org; Mon, 20 Mar 2017 14:10:13 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cpy0j-00013Z-4t for pgsql-performance@arkaria.postgresql.org; Mon, 20 Mar 2017 14:10:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cpxyw-0003q5-ED; Mon, 20 Mar 2017 14:08:22 +0000 Received: from mxgate01.infotech-enterprises.com ([110.76.168.168] helo=mxgate01.cyient.com) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1cpxyr-00084I-97; Mon, 20 Mar 2017 14:08:21 +0000 X-IronPort-AV: E=Sophos;i="5.36,194,1486405800"; d="scan'208";a="65290761" Received: from unknown (HELO INFHYDEX10HT.corp.infotech-enterprises.com) ([172.17.0.189]) by mxgate01.cyient.com with ESMTP/TLS/DHE-RSA-AES256-SHA; 20 Mar 2017 19:22:52 +0530 Received: from CYINMBX1.CORP.CYIENT.COM (172.17.4.161) by INFHYDEX10HT.corp.infotech-enterprises.com (172.17.0.189) with Microsoft SMTP Server (TLS) id 14.3.224.2; Mon, 20 Mar 2017 19:38:13 +0530 Received: from CYINMBX4.CORP.CYIENT.COM (172.17.4.164) by CYINMBX1.CORP.CYIENT.COM (172.17.4.161) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.544.27; Mon, 20 Mar 2017 19:38:07 +0530 Received: from CYINMBX4.CORP.CYIENT.COM ([fe80::e40c:d4fe:9e0c:f465]) by CYINMBX4.CORP.CYIENT.COM ([fe80::e40c:d4fe:9e0c:f465%19]) with mapi id 15.01.0544.027; Mon, 20 Mar 2017 19:38:07 +0530 From: Dinesh Chandra 12108 To: John Gorman CC: "pgsql-performance@postgresql.org" , "pgsql-performance-owner@postgresql.org" Subject: Re: Auto generate number in Postgres-9.1. Thread-Topic: [PERFORM] Auto generate number in Postgres-9.1. Thread-Index: AdKhfwAfZEZINCnoSxGDchgEFLEA3f//paCAgAAB7wD//5+kgA== Date: Mon, 20 Mar 2017 14:08:07 +0000 Message-ID: References: <97da050c-395c-7205-c5e9-95e7fdf13fde@berkus.org> <0A1B0B276DEE6441A2E68EB66D4540DAE6869132@winex2.eldocomp.com> In-Reply-To: <0A1B0B276DEE6441A2E68EB66D4540DAE6869132@winex2.eldocomp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [172.17.4.81] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-Pg-Spam-Score: -4.2 (----) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org Hi, Thanks for your immediate response!!!! Its working fine when we insert a new row. But on deletion it's not automatically re-adjusting the id's. Do I need to create trigger for this?? Regards, Dinesh Chandra |Database administrator (Oracle/PostgreSQL)| Cyient Ltd. Noida. -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owne= r@postgresql.org] On Behalf Of John Gorman Sent: 20 March, 2017 7:20 PM To: pgsql-performance@postgresql.org; pgsql-performance-owner@postgresql.org Subject: Re: [PERFORM] Auto generate number in Postgres-9.1. Sequences are stored as a separate object in PostgreSQL. Here in this example table and you can see that rec_id is a sequence number= and that the object name is: whiteboards_rec_id_seq mydb=3D> \d whiteboards Table "public.whiteboards" Column | Type | Mod= ifiers ---------------+-----------------------------+-------------------------- ---------------+-----------------------------+-------------------------- ---------------+-----------------------------+---------- rec_id | integer | not null default nextval('wh= iteboards_rec_id_seq'::regclass) board_name | character varying(24) | not null board_content | text | not null updatets | timestamp without time zone | default now() Indexes: "whiteboards_pkey" PRIMARY KEY, btree (rec_id) Now I can display the whiteboards_rec_id_seq object mydb=3D> \dS whiteboards_rec_id_seq Sequence "public.whiteboards_rec_id_seq" Column | Type | Value ---------------+---------+------------------------ sequence_name | name | whiteboards_rec_id_seq last_value | bigint | 12 start_value | bigint | 1 increment_by | bigint | 1 max_value | bigint | 9223372036854775807 min_value | bigint | 1 cache_value | bigint | 1 log_cnt | bigint | 31 is_cycled | boolean | f is_called | boolean | t -----Original Message----- From: pgsql-performance-owner@postgresql.org [mailto:pgsql-performance-owne= r@postgresql.org] On Behalf Of Josh Berkus Sent: Monday, March 20, 2017 6:43 AM To: Dinesh Chandra 12108; pgsql-performance-owner@postgresql.org Cc: pgsql-performance@postgresql.org Subject: Re: [PERFORM] Auto generate number in Postgres-9.1. Dinesh, > I have to add one column "ID" in postgres table which will generate > 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 trigg= er to the table. -- Josh Berkus Containers & Databases Oh My! -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance ________________________________ DISCLAIMER: This email message is for the sole use of the intended recipient(s) and may= contain confidential and privileged information. Any unauthorized review, = use, disclosure or distribution is prohibited. If you are not the intended = recipient, please contact the sender by reply email and destroy all copies = of the original message. Check all attachments for viruses before opening t= hem. All views or opinions presented in this e-mail are those of the author= and may not reflect the opinion of Cyient or those of our affiliates. --=20 Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance