Re: CHECK constraint removing brackets
От | Scott Marlowe |
---|---|
Тема | Re: CHECK constraint removing brackets |
Дата | |
Msg-id | dcc563d11001111214p3cd20de4rf65d8d591b3e4cca@mail.gmail.com обсуждение исходный текст |
Ответ на | CHECK constraint removing brackets (Andy Shellam <andy-lists@networkmail.eu>) |
Список | pgsql-sql |
On Mon, Jan 11, 2010 at 12:49 PM, Andy Shellam <andy-lists@networkmail.eu> 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. and invoice_id IS NULL is the proper nomenclature. Also, something <> NULL makes no sense, because we don't know what NULL is, so that becomes something IS NOT NULL Also != is not proper SQL, although many dbs understand it, <> is the proper way to write NOT EQUAL TO. > However PostgreSQL (8.4.2) converts this to the following: > > state = 'Unconfirmed'::client.order_state AND invoice_id = NULL::integer OR state <> 'Unconfirmed'::client.order_stateAND invoice_id <> NULL::integer ANDs have priority of ORs so the removal of the parenthesis makes no great change here. also, SQL standard is <> not !=. I'm guessing the real problems here are your NULL handling. See if changing it to IS NULL / IS NOT NULL gets you what you want.
В списке pgsql-sql по дате отправления: