Cast Operator Precedence

Поиск
Список
Период
Сортировка
Искать

Cast Operator Precedence

От:
"David E. Wheeler" <david@justatheory.com>
Дата:
Hackers,

I found this surprising:
david=# CREATE DOMAIN STATUS AS INTEGER CHECK ( VALUE IN (1, 2, 3) );
CREATE DOMAIN

david=# select -4::status;
ERROR:  value for domain status violates check constraint "status_check"

david=# select -1::status;?column? 
----------      -1
(1 row)

david=# select (-1)::status;
ERROR:  value for domain status violates check constraint "status_check"

So I guess the precedence of :: is higher than -?

Thanks,

David



Re: Cast Operator Precedence

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"David E. Wheeler"  writes:
> So I guess the precedence of :: is higher than -?

Sure.  Otherwise, you might get the wrong semantics of "-".

http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-PRECEDENCE
		regards, tom lane


Re: Cast Operator Precedence

От:
"David E. Wheeler" <david@justatheory.com>
Дата:
On Sep 11, 2012, at 4:39 PM, Tom Lane  wrote:

> Sure.  Otherwise, you might get the wrong semantics of "-".
> 
> http://www.postgresql.org/docs/9.2/static/sql-syntax-lexical.html#SQL-PRECEDENCE

Well, I guess that's what I get for writing test in literal SQL pushed through psql. Prepared statements FTW!

David


FAQ