tags:

views:

32

answers:

2

Is it possible to alter a table to add a new column and make that column a foreign key to another table in a single command in Postgresql? "alter table x add column y id references z(id)" doesn't seem to work as I had hoped.

+2  A: 

You can do it. What is "y id"? May be

alter table x add column y int references z(id)
msi77
+2  A: 
BEGIN
ALTER TABLE ... ADD COLUMN ...
ALTER TABLE ... ADD CONSTRAINT ...
COMMIT

You can't convince me it's not a single command :).

aib