Cast has higher precedence than -

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: <pgsql-hackers(at)postgresql(dot)org>
Subject: Cast has higher precedence than -
Date: 2015-05-04 00:39:29
Message-ID: 5546BFC1.9070009@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Given this domain...
CREATE DOMAIN loan.loan_amount numeric(7,2) --loan.loan_amount_raw
CONSTRAINT loan_amount__greater_equal_0 CHECK( VALUE >= 0 )
CONSTRAINT loan_amount__less_equal_20000 CHECK( VALUE <= 20000 )
;

I was rather surprised by

select -1::loan.loan_amount;
?column?
----------
-1.00
(1 row)

The problem is that :: binds more tightly than -:

select (-1)::loan.loan_amount;
ERROR: value for domain loan.loan_amount violates check constraint
"loan_amount__greater_equal_0"

Is this by design? If not, any ideas how bad it'd be to fix?
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2015-05-04 00:54:08 Re: Cast has higher precedence than -
Previous Message Andrew Dunstan 2015-05-03 23:41:36 Re: pgsql: Add transforms feature