Re: [GENERAL] Negative numbers to DOMAIN casting - Mailing list pgsql-general

From Tom Lane
Subject Re: [GENERAL] Negative numbers to DOMAIN casting
Date
Msg-id 18047.1481727197@sss.pgh.pa.us
Whole thread Raw
In response to [GENERAL] Negative numbers to DOMAIN casting  (Matija Lesar <matija.lesar@gmail.com>)
Responses Re: [GENERAL] Negative numbers to DOMAIN casting
List pgsql-general
Matija Lesar <matija.lesar@gmail.com> writes:
> I have uint4 domain created like this:
> CREATE DOMAIN uint4 AS int8
>    CHECK(VALUE BETWEEN 0 AND 4294967295);

> If I try to cast negative number to this domain check constraint is not
> validated:
> SELECT -1::uint4, pg_typeof(-1::uint4), 1::uint4, pg_typeof(1::uint4);

:: binds tighter than minus, so you would need to write these like
"(-1)::uint4" to get the behavior you're expecting.  See

https://www.postgresql.org/docs/9.5/static/sql-syntax-lexical.html#SQL-PRECEDENCE

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] PostgreSQL 9.6.1: Debug window does not load functionsql
Next
From: Adrian Klaver
Date:
Subject: Re: [GENERAL] Install doesnt set SuperUser PW