RE: ALTER TABLE...ADD CONSTRAINT?

Started by Christopher Kings-Lynneabout 25 years ago2 messages
#1Christopher Kings-Lynne
chriskl@familyhealth.com.au

Is anybody working on:

alter table <table> add constraint <name> primary key(column,...);

or

alter table <table> add constraint <name> unique(column,...);

or

alter table drop constraint

I'd be more than happy to work on either of the above in the current
implementation, however - I'm not sure it'd be worth it, given that the
constraints system might be up for a reimplementation.

I guess this is not really a small task as it relates to unifying
constraint handling, but for the PK & unique constraints at least, we must
already have code that does the work - all(?) that has to happen
is to make
sure the ALTER command calls it...is that right?

That is a thought - can someone point me to the C file that handles CREATE
TABLE so I can see how it's done? I can't for the life of me find that bit
of code!

Chris

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Christopher Kings-Lynne (#1)
Re: RE: ALTER TABLE...ADD CONSTRAINT?

"Christopher Kings-Lynne" <chriskl@familyhealth.com.au> writes:

can someone point me to the C file that handles CREATE
TABLE so I can see how it's done?

backend/parser/analyze.c has the preprocessing (see
transformCreateStmt). Actual execution starts in
backend/commands/creatinh.c, and there's also important code in
backend/catalog/heap.c.

Plus subroutines scattered here, there, and everywhere :-(.

You really won't get far in reading the PG sources until you have
a tool that will quickly find the definition (and optionally all uses)
of any particular symbol you are interested in. I'm partial to glimpse,
but you could also use ctags/etags or some other indexing program.

regards, tom lane