Cast Operator Precedence

Started by David E. Wheelerover 13 years ago3 messages
#1David 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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: David E. Wheeler (#1)
Re: Cast Operator Precedence

"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

#3David E. Wheeler
david@justatheory.com
In reply to: Tom Lane (#2)
1 attachment(s)
Re: Cast Operator Precedence

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

Attachments:

smime.p7sapplication/pkcs7-signature; name=smime.p7sDownload