Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 99705634151 for ; Tue, 23 Jun 2009 12:32:07 -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 26135-09 for ; Tue, 23 Jun 2009 12:32:04 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from jupiter.marktest.pt (delta.marktest.pt [80.251.174.116]) by mail.postgresql.org (Postfix) with ESMTP id 624946339ED for ; Tue, 23 Jun 2009 12:32:03 -0300 (ADT) Received: from suite (suite.marktest.pt [10.61.90.236]) by jupiter.marktest.pt with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id K0H2VHHH; Tue, 23 Jun 2009 16:32:01 +0100 Message-ID: <070201c9f417$c0e29630$ec5a3d0a@marktestcr.marktest.pt> From: "Oliveiros Cristina" To: , "Harald Fuchs" References: Subject: Re: Composite primary keys Date: Tue, 23 Jun 2009 16:32:01 +0100 MIME-Version: 1.0 Content-Type: text/plain; format=flowed; charset="iso-8859-1"; reply-type=original Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2900.2180 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=0 required=5 tests=AWL=-0.000, STOX_REPLY_TYPE=0.001 X-Spam-Level: X-Archive-Number: 200906/93 X-Sequence-Number: 32698 Howdy! When you say that pg accepts "this" silently instead of complaining what are you referring to exactly? First Insert? Why wouldn't it work after all ? What will happen is that when you try to insert a new record without specifying the id column you'll get an error informing that primary key constraint is being violated. But IMHO the first INSERT is legal SQL.... Best, Oliveiros ----- Original Message ----- From: "Harald Fuchs" To: Sent: Tuesday, June 23, 2009 4:14 PM Subject: [SQL] Composite primary keys >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. > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql