Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fRcbv-0001Rh-AB for pgsql-general@arkaria.postgresql.org; Sat, 09 Jun 2018 12:04:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fRcbu-0002g4-1w for pgsql-general@arkaria.postgresql.org; Sat, 09 Jun 2018 12:04:46 +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.89) (envelope-from ) id 1fRcbt-0002fu-Pr for pgsql-general@lists.postgresql.org; Sat, 09 Jun 2018 12:04:45 +0000 Received: from mx.nsu.ru ([84.237.50.39]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fRcbp-0005IB-PF for pgsql-general@postgresql.org; Sat, 09 Jun 2018 12:04:44 +0000 Received: from Debian-exim by mx.nsu.ru with local (Exim 4.72) (envelope-from ) id 1fRcbm-0004a2-Hd for pgsql-general@postgresql.org; Sat, 09 Jun 2018 19:04:38 +0700 Received: from [84.237.50.47] (helo=regency.nsu.ru) by mx.nsu.ru with esmtp (Exim 4.72) (envelope-from ) id 1fRcbm-0004Zn-FZ; Sat, 09 Jun 2018 19:04:38 +0700 Received: from regency.nsu.ru (localhost [127.0.0.1]) by regency.nsu.ru (8.14.2/8.14.2) with ESMTP id w59COUvq003840; Sat, 9 Jun 2018 18:24:31 +0600 (NOVT) (envelope-from danfe@regency.nsu.ru) Received: (from danfe@localhost) by regency.nsu.ru (8.14.2/8.14.2/Submit) id w59COP7E003827; Sat, 9 Jun 2018 19:24:25 +0700 (+07) (envelope-from danfe) Date: Sat, 9 Jun 2018 19:24:25 +0700 From: Alexey Dokuchaev To: Adrian Klaver Cc: pgsql-general@postgresql.org Subject: Re: (2^63 - 1)::bigint => out of range? (because of the double precision) Message-ID: <20180609122425.GA2680@regency.nsu.ru> References: <20180608172323.GA32312@regency.nsu.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2.1i X-KLMS-Rule-ID: 3 X-KLMS-Message-Action: skipped X-KLMS-AntiSpam-Status: not scanned, whitelist X-KLMS-AntiPhishing: not scanned, whitelist X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.705, not scanned, whitelist List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Fri, Jun 08, 2018 at 10:30:45AM -0700, Adrian Klaver wrote: > On 06/08/2018 10:23 AM, Alexey Dokuchaev wrote: > >I've decided to run some tests to see how my tables' ids would survive > >when their yielding sequences would start hitting their MAXVALUE's, by > >doing some "SELECT setval('foo_id_seq', ~maxbigint)". As I don't like > >to hardcode numbers (esp. huge numbers, because sequences are always[*] > >bigint's) > > Not always, bigints are just the default. All those cases where folks > use the serial 'type' are getting an int sequence: > > \d+ serial_test2_id_seq > Sequence "public.serial_test2_id_seq" > Type | Start | Minimum | Maximum | Increment | Cycles? | Cache > ---------+-------+---------+------------+-----------+---------+------- > integer | 1 | 1 | 2147483647 | 1 | no | 1 Apparently this is only in 10+, while I'm kind of confined to 9.x ATM. > >What is the rationale for (int ^ int) to return double precision rather > >than numeric? I am missing something obvious here? > > Not sure, someone else will have to explain. Tom already did, thanks Tom! > >On a tangentally related note, why is "NO CYCLE" is the default > >for sequences? > > My guess is because sequences are often used to provide numbers for a > PRIMARY KEY and NO CYCLE is a heads up for key duplication before the > PK code kicks in. OK, but what about highly volatile tables for come-and-go type of things? Think of a session pool, or task queue. I want to use NO CYCLE for this kind of tables as it would allow me to never worry about hitting "nextval: reached maximum value of sequence" error, recycle ids (because they come and go), and still be safe because PK constraint protects me. Any flaws in this vision of mine? ./danfe