From: | Reece Hart <reece(at)harts(dot)net> |
---|---|
To: | Matthew Terenzio <matt(at)jobsforge(dot)com> |
Cc: | PostgreSQL general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: not null across multiple columns |
Date: | 2006-11-03 00:29:16 |
Message-ID: | 1162513756.19432.174.camel@snafu.site |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, 2006-11-02 at 19:10 -0500, Matthew Terenzio wrote:
> suppose you wanted to be certain that either one of two or more
> columns were present
>
> Like in a user table, either a username or an email need to be present
> to create a row.
>
> You can't use not null because it's an either or situation.
>
> what's the best method to accomplish this sort of constraint?
See check constraints:
http://www.postgresql.org/docs/8.1/interactive/ddl-constraints.html#AEN1954
I suppose you seek something like this:
create table people (
name text,
email text,
constraint valid_name_or_email
check (name is not null or email is not null)
);
Cheers,
Reece
--
Reece Hart, http://harts.net/reece/, GPG:0x25EC91A0
From | Date | Subject | |
---|---|---|---|
Next Message | Robert Balzli Jr | 2006-11-03 00:57:49 | I can not add up columns when using a left outer join. Any ideas as to why? |
Previous Message | George Pavlov | 2006-11-03 00:26:20 | Re: not null across multiple columns |