Skip site navigation (1) Skip section navigation (2)

Adding not null check constaint to list of columns

From: plu 12 <plutard12(at)hotmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Adding not null check constaint to list of columns
Date: 2009-01-10 20:17:11
Message-ID: BLU115-W23378CB54670A002DDFC42A6DA0@phx.gbl (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
I have a table that contains four fields that need to be either all null or none null.

I can add a check like so:

    (col1 IS NULL AND col2 IS NULL AND col3 IS NULL and col4 IS NULL)
    NOT (col1 IS NULL OR col2 IS NULL OR col3 IS NULL OR col4 IS NULL)  

But is there a simpler way to declare that? I looked at coalesce() but that seems to require that all the columns have the same type.

Windows Liveā„¢ HotmailĀ®: Chat. Store. Share. Do more with mail.


pgsql-novice by date

Next:From: mltasmaniacDate: 2009-01-11 02:36:46
Subject: Foreign Keys
Previous:From: Tom LaneDate: 2009-01-10 17:42:59
Subject: Re: How to release a transaction lock on a table

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group