How do I create a check constraint that is based on age difference?

From: Justin <aa2(at)bigpond(dot)net(dot)au>
To: pgsql-general(at)postgresql(dot)org
Subject: How do I create a check constraint that is based on age difference?
Date: 2001-01-05 05:37:54
Message-ID: 01010516375400.15651@justin
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all,

How do I create a 'check' constraint on a date column, so that it will only
accept dates of at least 28 years ago from the date of entry? For example,
only allowing dates of birth of people who are older than 28.

i.e.

create table foo (name varchar(40), dob date check(date('dob') < date('now' -
28 years)));

This doesn't work. I don't understand how to do addition, subtraction, etc
with date fields.

Regards and best wishes,

Justin Clift
Database Administrator

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Anthony E . Greene 2001-01-05 06:11:51 Re: Test for existence of Table
Previous Message Anthony E . Greene 2001-01-05 05:06:17 Re: pg_dump return status..