Search Postgresql Archives

Re: not null across multiple columns

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux