Composite primary keys

From: Harald Fuchs <hari(dot)fuchs(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: Composite primary keys
Date: 2009-06-23 15:14:36
Message-ID: pu1vpb2d9f.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2009-06-23 15:26:59 Re: Composite primary keys
Previous Message James Kitambara 2009-06-23 06:56:17 Re: Find periods for a given... action set?