Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Tom Lane
Andy Shellam writes: > I know about the <> and !=, for some reason != has always made better sense > to me to read, so I tend to write it that way. Yeah, a lot of people prefer != ... that's why we provide it as an alias for <>. There's no functional difference. regards

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Andy Shellam
Hi Tom and Scott, > > I think your real problem is that you're trying to use "= NULL" and > "!= NULL" where you should say IS NULL or IS NOT NULL. Argh such a school-boy error! This is the first bit of database programming I've done for about 2 months, and I hadn't switched my C++ brain off.

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Tom Lane
Andy Shellam writes: > With the above in mind, I decided on the following check to enforce this: > (state = 'Unconfirmed'::client.order_state AND invoice_id = NULL) OR (state > != 'Unconfirmed'::client.order_state AND invoice_id != NULL) > However PostgreSQL (8.4.2) converts this to the followi

Re: [SQL] CHECK constraint removing brackets

2010-01-11 Thread Scott Marlowe
On Mon, Jan 11, 2010 at 12:49 PM, Andy Shellam wrote: > With the above in mind, I decided on the following check to enforce this: > > (state = 'Unconfirmed'::client.order_state AND invoice_id = NULL) OR (state > != 'Unconfirmed'::client.order_state AND invoice_id != NULL) Nothing can = null. an

[SQL] CHECK constraint removing brackets

2010-01-11 Thread Andy Shellam
Hi, I notice this had been raised as a bug (and subsequently over-ruled) so I'm asking how I can achieve the following business rule. I have an order table which has an invoice_id column that links to an invoice table (an order can only have 1 invoice, but one invoice can have multiple orders.