Reputation: 1920
I stumbled upon this S.O question, which mentions that a check constraint has to be written like this:
CHECK (ts >= timestamp '2015-08-11 00:00:00' AND ts < timestamp '2015-08-12 00:00:00')
I am personally writing my type casts like this :
CHECK (ts >= '2015-08-11 00:00:00'::timestamp AND ts < '2015-08-12 00:00:00'::timestamp)
Is 'timestamp' a type cast in the first example ? Are both checks equivalent ? Is there any performance difference between the two ?
Upvotes: 0
Views: 39
Reputation:
The first syntax: '2015-08-11 18:30:00'
is standard ANSI SQL to write a timestamp literal, this is also used for dates: date '2015-08-11'
or just a time value: time '18:30:00'
. This is a "constant" value, not a "cast" similar to simply writing 'foobar'
as a varchar constant.
The second form is a cast from a text value to a timestamp and is Postgres specific.
Upvotes: 1