pg.ddx.io pgsql-admin@postgresql.org mailing list archive
help / color / mirror / Atom feedIs it possible to create a CHECK constraint for my use case?
3+ messages / 3 participants
[nested] [flat]
* Is it possible to create a CHECK constraint for my use case?
@ 2012-01-31 08:11 Gnanakumar <gnanam@zoniac.com>
0 siblings, 2 replies; 3+ messages in thread
From: Gnanakumar @ 2012-01-31 08:11 UTC (permalink / raw)
To: 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
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Is it possible to create a CHECK constraint for my use case?
@ 2012-01-31 08:33 Thomas Kellerer <spam_eater@gmx.net>
parent: Gnanakumar <gnanam@zoniac.com>
1 sibling, 0 replies; 3+ messages in thread
From: Thomas Kellerer @ 2012-01-31 08:33 UTC (permalink / raw)
To: pgsql-admin
Gnanakumar, 31.01.2012 09:11:
> Hi,
>
> Our Production server is running PostgreSQL v8.2.22 on CentOS5.2.
You know that 8.2 is "end-of-live"?
http://www.postgresql.org/support/versioning/
> 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?
Something like this:
check ( (managertype = 2) or (managertype = 1 and managerid is not null) )
Not sure if the condition (managertype = 2) is actually needed, if the managertype is already constrained to 1/2 but I can't test it right now.
Thomas
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Is it possible to create a CHECK constraint for my use case?
@ 2012-02-01 01:04 Walter Hurry <walterhurry@lavabit.com>
parent: Gnanakumar <gnanam@zoniac.com>
1 sibling, 0 replies; 3+ messages in thread
From: Walter Hurry @ 2012-02-01 01:04 UTC (permalink / raw)
To: pgsql-admin
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2012-02-01 01:04 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-01-31 08:11 Is it possible to create a CHECK constraint for my use case? Gnanakumar <gnanam@zoniac.com>
2012-01-31 08:33 ` Thomas Kellerer <spam_eater@gmx.net>
2012-02-01 01:04 ` Walter Hurry <walterhurry@lavabit.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox