dbTalk Databases Forums  

check constraint on other column

comp.databases.postgresql comp.databases.postgresql


Discuss check constraint on other column in the comp.databases.postgresql forum.



Reply
 
Thread Tools Display Modes
  #11  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM






Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
  #12  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM






Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
  #13  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM



Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
  #14  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM



Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
  #15  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM



Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
  #16  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM



Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
  #17  
Old   
Laurenz Albe
 
Posts: n/a

Default Re: check constraint on other column - 09-09-2008 , 01:21 AM



Generale Cluster <alexunsampdoriano (AT) unsampdorianosoftmasters (DOT) net> wrote:
Quote:
is it possible to define a check with the following rules, without using
a trigger?

When inserting a value in field1:
- if field2=true then field1 must be 0
- if field2=false then field1 may be any number

I've thought about this:
CHECK ((field2=true AND field1=0) OR (field2=false AND field1>0))

is it right?
According to your requirements, I would rather expect

CHECK ((field2=true AND field1=0) OR (field2=false))

Yours,
Laurenz Albe


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.