Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UaAI4-00027s-8q for pgsql-bugs@arkaria.postgresql.org; Wed, 08 May 2013 19:44:40 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UaAI3-00087N-Ka for pgsql-bugs@arkaria.postgresql.org; Wed, 08 May 2013 19:44:39 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UaAI2-00087D-UZ for pgsql-bugs@postgresql.org; Wed, 08 May 2013 19:44:39 +0000 Received: from mbx.knossos.net.nz ([202.160.48.10]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UaAHz-0000Zm-3l for pgsql-bugs@postgresql.org; Wed, 08 May 2013 19:44:38 +0000 Received: from [10.1.1.3] (60-234-150-59.bitstream.orcon.net.nz [60.234.150.59]) (authenticated bits=0) by mbx.knossos.net.nz (8.14.4/8.14.4) with ESMTP id r48JiQom010270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Thu, 9 May 2013 07:44:28 +1200 Message-ID: <518AAB1A.9060302@archidevsys.co.nz> Date: Thu, 09 May 2013 07:44:26 +1200 From: Gavin Flower Organization: ArchiDevSys User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130328 Thunderbird/17.0.5 MIME-Version: 1.0 To: andras.vaczi@zalando.de CC: pgsql-bugs@postgresql.org Subject: Re: BUG #8141: multi-column check expression evaluating to NULL References: In-Reply-To: Content-Type: multipart/alternative; boundary="------------000704010705090300090305" X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org This is a multi-part message in MIME format. --------------000704010705090300090305 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 09/05/13 01:07, andras.vaczi@zalando.de wrote: > The following bug has been logged on the website: > > Bug reference: 8141 > Logged by: Andras Vaczi > Email address: andras.vaczi@zalando.de > PostgreSQL version: 9.1.9 > Operating system: linux/Ubuntu 12.10 > Description: > > Consider the following table with a CHECK constraint: > > CREATE TABLE check_test > ( > id integer NOT NULL, > col integer, > CONSTRAINT unique_with_null_check1 CHECK (col >= 1 AND id < 20) > ); > [...] if 'id' is the primary key, then the table should be defined as: CREATE TABLE check_test ( id integer PRIMARY KEY, col integer NOT NULL, CONSTRAINT unique_with_null_check1 CHECK (col >= 1 AND id < 20) ); Because: 1. 'PRIMARY KEY ' implies 'NOT NULL' and also 'UNIQUE', and so an index is created for 'id' (index is required to enforce uniqueness) 2. you are testing that 'col' has a certain type of numeric value, so this logically implies that it is 'NON NULL', but you actually have to tell progress explicitly tat you want it to be 'NON NULL' Cheers, Gavin --------------000704010705090300090305 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mbx.knossos.net.nz id r48JiQom010270
On 09/05/13 01:07, andras.vaczi@zalando.de wrote:
The following bug has been logged on the website:

Bug reference:      8141
Logged by:          Andras Vaczi
Email address:      andras.vaczi@zalando.de
PostgreSQL version: 9.1.9
Operating system:   linux/Ubuntu 12.10
Description:       =20

Consider the following table with a CHECK constraint:

CREATE TABLE check_test
(
  id integer NOT NULL,
  col integer,
  CONSTRAINT unique_with_null_check1 CHECK (col >=3D 1 AND id < 20)
);

[...]

if 'id' is the primary key, then the table should be defined as:
CREATE TABLE check_test
(
  id  integer PRIMARY KEY,
  col integer NOT NULL,
  CONSTRAINT unique_with_null_check1 CHECK (col >=3D 1 AND id < 20)
);
Because:
  1. =C2=A0'PRIMARY KEY ' implies 'NOT NULL' and also 'UNIQUE', and so an index is created for 'id'
    (index is required to enforce uniqueness)

  2. you are testing that 'col' has a certain type of numeric value, so this logically implies that it is 'NON NULL', but you actually have to tell progress explicitly tat you want it to be 'NON NULL'


Cheers,
Gavin
--------------000704010705090300090305--