"Christopher Kings-Lynne" <chriskl@familyhealth.com.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