From: | brian <brian(at)zijn-digital(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: date ranges |
Date: | 2007-08-04 13:18:09 |
Message-ID: | 46B47C91.60101@zijn-digital.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
jo wrote:
> Hello,
>
> I would like to know if there's a simple way to customize the range for
> dates,
> to avoid people insert dates before 1900 and after 2020, for example.
>
test=# CREATE TABLE foo (
id SERIAL PRIMARY KEY,
dt DATE,
CHECK (
EXTRACT('year' FROM dt) >= 1900 AND EXTRACT('year' FROM dt) < 2020
)
);
test=# INSERT INTO foo (dt) VALUES ('1984-03-02');
INSERT 0 1
test=# INSERT INTO foo (dt) VALUES ('1884-03-02');
ERROR: new row for relation "foo" violates check constraint "foo_dt_check"
test=# INSERT INTO foo (dt) VALUES ('2024-03-02');
ERROR: new row for relation "foo" violates check constraint "foo_dt_check"
There's probably a more elegant way to do this.
brian
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Glaesemann | 2007-08-04 13:19:10 | Re: date ranges |
Previous Message | Raymond O'Donnell | 2007-08-04 13:11:01 | Re: date ranges |