| From: | Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> |
|---|---|
| To: | Joo Paulo Batistella <batistellabr(at)yahoo(dot)com(dot)br> |
| Cc: | <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Constraint |
| Date: | 2002-07-16 16:23:31 |
| Message-ID: | 20020716092141.C50015-100000@megazone23.bigpanda.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Tue, 16 Jul 2002, Joo Paulo Batistella wrote:
> Hi.
>
> I would like to make the following constraint in my
> db.
>
> I have three fields:
> -field1
> -field2
> -field3
>
> If field1 is not null, then field2 and field3 MUST be
> null. Again, if field2 is not null, then field1 and
> field3 MUST be null, and so on...
>
> Is it possible?
> How can I do that?
Should be possible with a table check constraint.
There's probably a better way, but:
check(
(a is not null and b is null and c is null) or
(b is not null and a is null and c is null) or
(c is not null and a is null and b is null)
)
If they can all be null, you need an additional
clause to say that.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Neil Conway | 2002-07-16 16:25:06 | Re: COPY seems to work, but no data in the table |
| Previous Message | Neil Conway | 2002-07-16 16:18:22 | Re: Inquiry From Form [pgsql] |