Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZjeHK-0002AO-45 for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Oct 2015 02:16:26 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZjeHJ-0002bd-F2 for pgsql-bugs@arkaria.postgresql.org; Wed, 07 Oct 2015 02:16:25 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1Zjawt-0004ge-Qx for pgsql-bugs@postgresql.org; Tue, 06 Oct 2015 22:43:07 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.84) (envelope-from ) id 1Zjawq-0000fT-2Y for pgsql-bugs@postgresql.org; Tue, 06 Oct 2015 22:43:06 +0000 MIME-Version: 1.0 Subject: BUG #13665: Foreign Key constraint doesn't work To: pgsql-bugs@postgresql.org From: irina.guberman@gmail.com Date: Tue, 06 Oct 2015 22:42:12 +0000 Message-ID: <20151006224212.632.12147@wrigleys.postgresql.org> X-Pg-Spam-Score: -0.3 (/) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit 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 The following bug has been logged on the website: Bug reference: 13665 Logged by: Irina Email address: irina.guberman@gmail.com PostgreSQL version: 9.4.4 Operating system: Mac Description: I can enter rows with null value in a foreign key constrained column. I ran into this with my own schema, but then tried examples straight out of PostgreSQL constraints documentation http://www.postgresql.org/docs/9.4/static/ddl-constraints.html and was able to reproduce it: CREATE TABLE products ( product_no integer PRIMARY KEY, name text, price numeric ); CREATE TABLE orders ( order_id integer PRIMARY KEY, product_no integer REFERENCES products (product_no), quantity integer ); -- INSERT order WITHOUT product_no insert into orders(order_id, quantity) values(123,10) Query returned successfully: one row affected, 13 ms execution time. select * from orders; returns the one row entered above Despite the documentation (and general sql knowledge): "Now it is impossible to create orders with non-NULL product_no entries that do not appear in the products table. We say that in this situation the orders table is the referencing table and the products table is the referenced table. Similarly, there are referencing and referenced columns." -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs