Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 09A016339ED for ; Tue, 23 Jun 2009 12:14:54 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 22538-09 for ; Tue, 23 Jun 2009 12:14:50 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by mail.postgresql.org (Postfix) with ESMTP id 9E1986327DD for ; Tue, 23 Jun 2009 12:14:50 -0300 (ADT) Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MJ7hw-0007QH-AX for pgsql-sql@postgresql.org; Tue, 23 Jun 2009 15:14:48 +0000 Received: from srv.protecting.net ([212.126.218.242]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 23 Jun 2009 15:14:48 +0000 Received: from hari.fuchs by srv.protecting.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 23 Jun 2009 15:14:48 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Harald Fuchs Subject: Composite primary keys Date: Tue, 23 Jun 2009 17:14:36 +0200 Lines: 30 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: srv.protecting.net X-Archive: encrypt User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux) Cancel-Lock: sha1:GCp9hCyaTl1m2lJBRJnzuJVW8KI= X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200906/91 X-Sequence-Number: 32696 I tried to throw some invalid SQL to PostgreSQL and found its reaction confusing: $ psql test psql (8.4beta2) Type "help" for help. test=# CREATE TABLE t1 ( test(# id serial NOT NULL, test(# name text NOT NULL, test(# PRIMARY KEY (id) test(# ); CREATE TABLE test=# CREATE TABLE t2 ( test(# id int NOT NULL REFERENCES t1, test(# language char(3) NULL, test(# txt text NOT NULL, test(# PRIMARY KEY (id, language) test(# ); CREATE TABLE Here's my first gripe: PostgreSQL accepts this silently instead of complaining. test=# INSERT INTO t1 (id, name) VALUES (1, 'text 1'); INSERT 0 1 test=# INSERT INTO t2 (id, language, txt) VALUES (2, NULL, 'text 1 no language'); ERROR: null value in column "language" violates not-null constraint And here's my second gripe: although PostgreSQL correctly rejects the INSERT it just has ignored my NULL specification.