Re: date ranges
| От | brian | 
|---|---|
| Тема | Re: date ranges | 
| Дата | |
| Msg-id | 46B47C91.60101@zijn-digital.com обсуждение исходный текст | 
| Ответ на | date ranges (jo <jose.soares@sferacarta.com>) | 
| Список | 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
		
	В списке pgsql-general по дате отправления: