Re: Table/Column Constraints

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Table/Column Constraints
Date: 2000-11-20 15:51:09
Message-ID: 27798.974735469@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

"Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au> writes:
> * I assume that the command is supposed to allow the dropping of unique,
> primary, foreign key and check constraints? Should 'not null' constraints
> also be included here?

Sure.

> * Unique constraints are implemented as indicies, so dropping a unique
> constraint maps to dropping the relevant index.

Or just marking the index non-unique. Dropping it altogether might be
bad for query performance.

> * Primary keys are implemented...how?? I can't for the life of me find
> where 'create table' occurs in the source code!

Primary key == UNIQUE NOT NULL, as far as I know, and there's also a
flag somewhere in the index associated with the UNIQUE constraint.

> * Check constraints. I seem to recall seeing code that implements check
> constraints as triggers, but I wrote a query that retrieves all triggers
> associated with a particular class and no check triggers were returned. How
> are check constraints implemented? How would you drop a check constraint?

No, check constraints are stored in pg_relcheck. Don't forget to update
the count in pg_class.relchecks.

> * Not null constraints. This seems to be a 'for completeness' constraint -
> I presume it's implemented as part of the attribute definition?

AFAIR it's just a bool in the pg_attribute row for the column.

> Also - is there some good reason why this hasn't been implemented yet? Is
> there some subtle reason, or is it just that no-one's bothered?

I think no one's got round to it; attention has focused on DROP COLUMN,
which is a great deal harder. If you feel like working on DROP
CONSTRAINT, go for it...

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Don Baccus 2000-11-20 16:07:52 building current sources
Previous Message Tom Lane 2000-11-20 15:43:02 RPM's -fsigned-char (Re: [COMMITTERS] pgsql/src/backend/utils/adt (cash.c))