Re: BUG #15071: Error in PostgreSQL-specific :: type cast
От | Tom Lane |
---|---|
Тема | Re: BUG #15071: Error in PostgreSQL-specific :: type cast |
Дата | |
Msg-id | 14545.1518794963@sss.pgh.pa.us обсуждение исходный текст |
Ответ на | Re: BUG #15071: Error in PostgreSQL-specific :: type cast (Daniel Gustafsson <daniel@yesql.se>) |
Список | pgsql-bugs |
Daniel Gustafsson <daniel@yesql.se> writes: >> On 16 Feb 2018, at 12:57, PG Bug reporting form <noreply@postgresql.org> wrote: >> PostgreSQL-specific :: type casts for lowest values of integer types are >> produce "Out of range" errors: >> >> SELECT -32768::smallint >> ^ERROR: smallint out of range > The parser will represents this as the numeric portion, 32768, and a “-“ in an > expression of type AEXPR_OP. Right. The point is that :: binds more tightly than unary minus[1], so this is read as "-(32768::smallint)", and the out-of-range failure is entirely appropriate. You can avoid the problem with (-32768)::smallint, or as you mentioned with '-32768'::smallint. While we hear complaints about this regularly, I do not think that changing the precedence order would be a good idea. It's at least conceivable that the behavior of the unary-minus operator would be different for different datatypes, so enforcing the datatype selection before applying the operator seems like the right decision from an abstract-data-type standpoint. (This argument explains why :: has such a high precedence to begin with.) You can even construct cases, admittedly lame, where changing the precedence would result in failures where there had been none before. regards, tom lane [1] https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-PRECEDENCE
В списке pgsql-bugs по дате отправления: