Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: Support ALTER TABLE ADD COLUMN colname REFERENCES tablename(colname); #32917

Closed
BramGruneir opened this issue Dec 6, 2018 · 16 comments · Fixed by #47082
Closed

sql: Support ALTER TABLE ADD COLUMN colname REFERENCES tablename(colname); #32917

BramGruneir opened this issue Dec 6, 2018 · 16 comments · Fixed by #47082
Assignees
Labels
A-schema-changes A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

Comments

@BramGruneir
Copy link
Member

This is currently unimplemented (and returns an error) but I don't think it would be hard to add. There's no worry about violating the constraint since the column is new.

It also points to #8855, but that's not the correct issue. So I'll send a PR to update the issue number to this one.

Assigning @vivekmenezes for triage.

@BramGruneir BramGruneir added this to the 2.2 milestone Dec 6, 2018
@vivekmenezes vivekmenezes removed their assignment Dec 6, 2018
@vivekmenezes vivekmenezes added A-schema-changes C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) labels Dec 6, 2018
@vivekmenezes vivekmenezes removed this from the 2.2 milestone Dec 6, 2018
@awoods187
Copy link
Contributor

This is needed for #5582 right?

@vivekmenezes
Copy link
Contributor

@awoods187 this looks like a small effort.

BramGruneir added a commit to BramGruneir/cockroach that referenced this issue Dec 13, 2018
And also clean up the wording to be more explicit.

The error for not being able to add a reference via alter was pointing to the
incorrect github ID cockroachdb#8855. It's been updated to point to cockroachdb#32917 instead.

Release note: None
craig bot pushed a commit that referenced this issue Dec 13, 2018
33144: sql: Uopdate unimplemented reference r=BramGruneir a=BramGruneir

And also clean up the wording to be more explicit.

The error for not being able to add a reference via alter was pointing to the
incorrect github ID #8855. It's been updated to point to #32917 instead.

Release note: None

Co-authored-by: Bram Gruneir <bram@cockroachlabs.com>
@solongordon
Copy link
Contributor

For what it's worth, I just hit this while writing a migration for the managed service console. Would be nice to support.

vivekmenezes added a commit to vivekmenezes/cockroach that referenced this issue Mar 13, 2019
This will eventually be fixed through cockroachdb#32917

Also added a unittest to check that this fails specifically for
a column needing a backfill.

Release note: None
vivekmenezes added a commit to vivekmenezes/cockroach that referenced this issue Mar 13, 2019
This will eventually be fixed through cockroachdb#32917

Also added a unittest to check that this fails specifically for
a column needing a backfill.

Release note: None
craig bot pushed a commit that referenced this issue Mar 13, 2019
35697: sql: improve error message while adding column with REFERENCE r=vivekmenezes a=vivekmenezes

This will eventually be fixed through #32917

Also added a unittest to check that this fails specifically for
a column needing a backfill.

Release note: None

Co-authored-by: Vivek Menezes <vivek@cockroachlabs.com>
@rolandcrosby
Copy link

@awoods187 can you help me understand the relative urgency of this? It sounds like it would help us add foreign keys transactionally but I'm not sure how much that buys us for ORM compat.

@awoods187
Copy link
Contributor

I'm not sure--it was needed for compat but a lot of work has changed here with FKs and ORMs. @jordanlewis do you know?

@rafiss rafiss added the A-sql-pgcompat Semantic compatibility with PostgreSQL label Feb 8, 2020
@jordanlewis
Copy link
Member

I'd like to tackle this soon. cc @rohany

@rohany rohany self-assigned this Mar 31, 2020
@rohany
Copy link
Contributor

rohany commented Mar 31, 2020

Just to clarify this is just adding a foreign key constraint on the column right

rohany added a commit to rohany/cockroach that referenced this issue Apr 6, 2020
Fixes cockroachdb#32917.

This PR adds support for the add column references
statement by allowing the foreign key building code
to use columns and indexes added in the current txn.
The schema changer already understands how to add
the combination of the three in the same transaction.

Release note (sql change): This PR adds support for the
`ALTER TABLE ... ADD COLUMN ... REFERENCES ...` syntax.
rohany added a commit to rohany/cockroach that referenced this issue Apr 27, 2020
Fixes cockroachdb#32917.

This PR adds support for the add column references
statement by allowing the foreign key building code
to use columns and indexes added in the current txn.
The schema changer already understands how to add
the combination of the three in the same transaction.

Release note (sql change): This PR adds support for the
`ALTER TABLE ... ADD COLUMN ... REFERENCES ...` syntax
for tables that are empty.
rohany added a commit to rohany/cockroach that referenced this issue Apr 27, 2020
Fixes cockroachdb#32917.

This PR adds support for the add column references
statement by allowing the foreign key building code
to use columns and indexes added in the current txn.
The schema changer already understands how to add
the combination of the three in the same transaction.

Release note (sql change): This PR adds support for the
`ALTER TABLE ... ADD COLUMN ... REFERENCES ...` syntax
for tables that are empty.
rohany added a commit to rohany/cockroach that referenced this issue Apr 30, 2020
Fixes cockroachdb#32917.

This PR adds support for the add column references
statement by allowing the foreign key building code
to use columns and indexes added in the current txn.
The schema changer already understands how to add
the combination of the three in the same transaction.

Release note (sql change): This PR adds support for the
`ALTER TABLE ... ADD COLUMN ... REFERENCES ...` syntax
for tables that are empty.
rohany added a commit to rohany/cockroach that referenced this issue Apr 30, 2020
Fixes cockroachdb#32917.

This PR adds support for the add column references
statement by allowing the foreign key building code
to use columns and indexes added in the current txn.
The schema changer already understands how to add
the combination of the three in the same transaction.

Release note (sql change): This PR adds support for the
`ALTER TABLE ... ADD COLUMN ... REFERENCES ...` syntax
for tables that are empty.
craig bot pushed a commit that referenced this issue May 4, 2020
47082: sql: support the ADD COLUMN ... REFERENCES syntax r=lucy-zhang a=rohany

Fixes #32917.

This PR adds support for the add column references
statement by allowing the foreign key building code
to use columns and indexes added in the current txn.
The schema changer already understands how to add
the combination of the three in the same transaction.

Release note (sql change): This PR adds support for the
`ALTER TABLE ... ADD COLUMN ... REFERENCES ...` syntax.

Co-authored-by: Rohan Yadav <rohany@alumni.cmu.edu>
@craig craig bot closed this as completed in 83caa70 May 4, 2020
@jordanlewis
Copy link
Member

Nice!

@proffalken
Copy link

\o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-schema-changes A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)
Projects
None yet
Development

Successfully merging a pull request may close this issue.