From: Tom Lane <tgl@sss.pgh.pa.us>
To: Alexey Dokuchaev <danfe@nsu.ru>
Cc: pgsql-general@postgresql.org
Subject: Re: (2^63 - 1)::bigint => out of range? (because of the double precision)
Date: Fri, 08 Jun 2018 13:49:29 -0400
Message-ID: <30538.1528480169@sss.pgh.pa.us> (raw)
In-Reply-To: <20180608172323.GA32312@regency.nsu.ru>
References: <20180608172323.GA32312@regency.nsu.ru>
Alexey Dokuchaev <danfe@nsu.ru> writes:
> What is the rationale for (int ^ int) to return double precision rather
> than numeric? I am missing something obvious here?
There are two ^ operators, one taking float8 and one taking numeric.
Since float8 is the preferred datatype in the numeric category
(i.e. the top of the implicit-casting hierarchy), the float8 operator
will be chosen unless one of the earlier disambiguation rules applies:
https://www.postgresql.org/docs/current/static/typeconv-oper.html
In this case, you need at least one input to be numeric, so that
rule 3c fires before rule 3d can.
You might argue that numeric should be the preferred type, but that
falls foul of the SQL standard, which is quite clear that only
numeric -> float8 can be an implicit cast, not the other direction.
(They word it in terms of casts between exact and approximate
numeric types, but that's the outcome.) The type resolution
heuristics break down pretty badly if the preferred type in a
category doesn't have implicit casts from every other type in the
category.
BTW, you could also just write 2.0^63 to get numeric.
> P.S. On a tangentally related note, why is "NO CYCLE" is the default
> for sequences?
(a) the SQL standard says so, (b) most people tend to expect serial
columns to not repeat values.
> [*] Per documentation, "The [SQL] standard's AS <data type> expression
> is not supported." Another "why is it so?" question, btw. ;-)
We didn't get around to implementing that till v10.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, danfe@nsu.ru
Subject: Re: (2^63 - 1)::bigint => out of range? (because of the double precision)
In-Reply-To: <30538.1528480169@sss.pgh.pa.us>
References: <20180608172323.GA32312@regency.nsu.ru> <30538.1528480169@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox