Re: Negative numbers to DOMAIN casting

From: Matija Lesar <matija(dot)lesar(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Negative numbers to DOMAIN casting
Date: 2016-12-15 06:43:40
Message-ID: CAPx3hmPkzdDdJVXT7Zivm5M3wzHf4C+oFDkY2GaPf3Ky-VWZKA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Tom,

thank you for the explanation.

Regards,
Matija Lesar

On 14 December 2016 at 15:53, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

> Matija Lesar <matija(dot)lesar(at)gmail(dot)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
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2016-12-15 07:37:38 Re: pg_dump and quoted identifiers
Previous Message David Steele 2016-12-15 03:43:12 Re: pgAudit_Analyze - parse error in pgaudit_analyze.log