Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpxhS-0006nE-M8 for pgsql-performance@arkaria.postgresql.org; Mon, 20 Mar 2017 13:50:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1cpxhS-0006JU-9P for pgsql-performance@arkaria.postgresql.org; Mon, 20 Mar 2017 13:50:18 +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 1cpxfg-0001Fo-3f; Mon, 20 Mar 2017 13:48:28 +0000 Received: from kilimanjaro.scorpionshops.com ([82.118.24.83]) by magus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cpxfc-0007gD-Sq; Mon, 20 Mar 2017 13:48:27 +0000 Received: from [10.0.5.121] (h-95-113.a137.corp.bahnhof.se [94.254.95.113]) by kilimanjaro.scorpionshops.com (Postfix) with ESMTPSA id C17E07BC614; Mon, 20 Mar 2017 14:48:23 +0100 (CET) Subject: Re: Auto generate number in Postgres-9.1. To: Josh Berkus , Dinesh Chandra 12108 , "pgsql-performance-owner@postgresql.org" References: <97da050c-395c-7205-c5e9-95e7fdf13fde@berkus.org> Cc: "pgsql-performance@postgresql.org" From: Andreas Karlsson Message-ID: <84f4e415-02ef-b22b-8a3e-6d95b66b660b@proxel.se> Date: Mon, 20 Mar 2017 14:48:23 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0 MIME-Version: 1.0 In-Reply-To: <97da050c-395c-7205-c5e9-95e7fdf13fde@berkus.org> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 8bit X-Pg-Spam-Score: -1.9 (-) 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 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 -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance