Is it possible to create a CHECK constraint for my use case?

From: "Gnanakumar" <gnanam(at)zoniac(dot)com>
To: <pgsql-admin(at)postgresql(dot)org>
Subject: Is it possible to create a CHECK constraint for my use case?
Date: 2012-01-31 08:11:00
Message-ID: 006c01ccdfef$e0396f60$a0ac4e20$@com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Hi,

Our Production server is running PostgreSQL v8.2.22 on CentOS5.2. We want
to enable a specific CHECK constraint for our application table as explained
below:

There are 2 columns in the table: "managertype" numeric(1) and "managerid"
numeric(10). "managertype" accepts only 2 valid values, either '1' or '2'.

managertype | managerid
---------------------------------
1 | null values NOT allowed
2 | null values allowed
---------------------------------

We want to enable a CHECK constraint based on 2 columns data in the table in
such a way that if "managertype" is 1, then null values are not allowed in
"managerid" column. In other words, I want to create a CHECK constraint
something like this: IF (managertype = 1) THEN managerid IS NOT NULL.

Is it possible to create a CHECK constraint for my use case explained above?

Regards,
Gnanam

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Thomas Kellerer 2012-01-31 08:33:19 Re: Is it possible to create a CHECK constraint for my use case?
Previous Message Tom Lane 2012-01-26 15:39:21 Re: extend column limit with blocksize does not work