Re: not null across multiple columns - Mailing list pgsql-general

From Reece Hart
Subject Re: not null across multiple columns
Date
Msg-id 1162513756.19432.174.camel@snafu.site
Whole thread Raw
In response to not null across multiple columns  (Matthew Terenzio <matt@jobsforge.com>)
List 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



pgsql-general by date:

Previous
From: "George Pavlov"
Date:
Subject: Re: not null across multiple columns
Next
From: louis gonzales
Date:
Subject: Re: Is there anyway to...