1

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.

0

2 Answers 2

3

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

alter table x add column y int references z(id)
Sign up to request clarification or add additional context in comments.

Comments

3
BEGIN
ALTER TABLE ... ADD COLUMN ...
ALTER TABLE ... ADD CONSTRAINT ...
COMMIT

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.