Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 818DAD45795 for ; Tue, 31 Jan 2012 21:05:23 -0400 (AST) Received: from plane.gmane.org ([80.91.229.3]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RsOdV-0001R7-3g for pgsql-admin@postgresql.org; Wed, 01 Feb 2012 01:05:23 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1RsOdH-0007Ee-5K for pgsql-admin@postgresql.org; Wed, 01 Feb 2012 02:05:07 +0100 Received: from cpc3-walt15-2-0-cust148.13-2.cable.virginmedia.com ([86.21.186.149]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Feb 2012 02:05:07 +0100 Received: from walterhurry by cpc3-walt15-2-0-cust148.13-2.cable.virginmedia.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Feb 2012 02:05:07 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-admin@postgresql.org From: Walter Hurry Subject: Re: Is it possible to create a CHECK constraint for my use case? Date: Wed, 1 Feb 2012 01:04:58 +0000 (UTC) Lines: 28 Message-ID: References: <006c01ccdfef$e0396f60$a0ac4e20$@com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: cpc3-walt15-2-0-cust148.13-2.cable.virginmedia.com User-Agent: Pan/0.135 (Tomorrow I'll Wake Up and Scald Myself with Tea; GIT 30dc37b master) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201201/148 X-Sequence-Number: 39060 On Tue, 31 Jan 2012 13:41:00 +0530, Gnanakumar wrote: > 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? Production server? Bollocks. It's homework. Look it up.