pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Joshua Tolley <eggyknap@gmail.com>
Cc: Harald Fuchs <hari.fuchs@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Composite primary keys
Date: Tue, 23 Jun 2009 15:15:17 -0400
Message-ID: <24680.1245784517@sss.pgh.pa.us> (raw)
In-Reply-To: <20090623184412.GG27474@eddie>
References: <pu1vpb2d9f.fsf@srv.protecting.net>
	<20090623184412.GG27474@eddie>

Joshua Tolley <eggyknap@gmail.com> writes:
> Primary keys are NOT NULL and UNIQUE. You can't have null values in a primary
> key.

On reflection I think the OP's beef is that we complain about this:

regression=# create table t (f1 int null not null);
ERROR:  conflicting NULL/NOT NULL declarations for column "f1" of table "t"

but not this:

regression=# create table t (f1 int null primary key);    
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "t_pkey" for table "t"
CREATE TABLE

even though the implied NOT NULL is really a conflict.  I think we could
fix that case if we cared to.  However, since the NULL clause is
forgotten about after parsing, there isn't anything we could do to raise
a complaint about doing it in two steps:

regression=# create table t (f1 int null);            
CREATE TABLE
regression=# alter table t add primary key(f1);
NOTICE:  ALTER TABLE / ADD PRIMARY KEY will create implicit index "t_pkey" for table "t"
ALTER TABLE

(barring remembering the NULL clause in the catalogs, which seems
entirely silly).  So I'm not sure how interesting it is to complain
about the single-command case.

			regards, tom lane



view thread (8+ messages)  latest in thread

Message-ID: <24680.1245784517@sss.pgh.pa.us>
Permalink:  ../24680.1245784517@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/24680.1245784517@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, eggyknap@gmail.com, hari.fuchs@gmail.com
  Subject: Re: Composite primary keys
  In-Reply-To: <24680.1245784517@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox