mak
mak

Reputation: 1183

How to add check constraint on time with a timestamp?

I need to add a constraint that time entered in a column is only after 8:00 am. I've tried

alter table toy_store ADD CHECK (store_opening_time > TIMESTAMP '2013-05-05 08:00:00');

This only allows entry of timestamp greater than 5th May 8:00 am. I want to write a query that checks if the entry is after 8:00 am notwithstanding the date.

Upvotes: 1

Views: 11199

Answers (1)

Ersin Tarhan
Ersin Tarhan

Reputation: 361

you can do it like this :

 alter table toy_store ADD CHECK (EXTRACT(HOUR FROM store_opening_time) > 8 || NULL);

Upvotes: 1

Related Questions