Search code examples
sqldatealterpgadmin-4

How to alter a table and add in a date column which doesn't allow dates before a certain date in sql?


I need an sql query to alter a table to add in a date column, which is the part I know how to do. What I don't know how to do is specify that the dates in the column need to be after a certain date.

My latest attempt:

ALTER TABLE <table name>
ADD constraint <constraint name>
CHECK (<column name>(date, 'YYYY-MM-DD') >= '2000-01-01');

I'm using pgadmin4.


Solution

  • How about this?

    ALTER TABLE t ADD constraint chk_t_col CHECK (col >= '2000-01-01');