Thread: Cast Operator Precedence
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
"David E. Wheeler" <david@justatheory.com> 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
On Sep 11, 2012, at 4:39 PM, Tom Lane <tgl@sss.pgh.pa.us> 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