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

Clarify known limitation on schema changes within transactions #4905

Closed
jseldess opened this issue Jun 7, 2019 · 1 comment · Fixed by #6145
Closed

Clarify known limitation on schema changes within transactions #4905

jseldess opened this issue Jun 7, 2019 · 1 comment · Fixed by #6145
Assignees
Labels

Comments

@jseldess
Copy link
Contributor

jseldess commented Jun 7, 2019

This known limitation states that arranging DML statements so they come after DDL statements should work, but it contradicts a few of these examples. And @joshimhoff confirmed that you can't, for example, add a column and then update its value within a single transaction.

@rafiss
Copy link
Contributor

rafiss commented Dec 5, 2019

The docs on the known limitations page should also be updated. The same wording is used in this section of the page linked in the original issue.

cockroachdb/cockroach#26508 tracks the mized DDL/DML transactions issue.

Here are some super simple cases that don't work:

create table t (a int primary key);
begin;
savepoint cockroach_restart;
alter table t add column e int;
select a,e from t;

ERROR: column "e" does not exist
SQLSTATE: 42703
create table t (a int primary key);
begin;
savepoint cockroach_restart;
alter table t add column e int;
update t set e = 1;

ERROR: column "e" does not exist
SQLSTATE: 42703

Note that the example in this section of the docs DOES work. (I.e., if the table is created inside the transaction, it works.)

  BEGIN;
  SAVEPOINT cockroach_restart;
  CREATE TABLE fruits (
        id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
        name STRING,
        color STRING
    );
  INSERT INTO fruits (name, color) VALUES ('apple', 'red');
  ALTER TABLE fruits ADD COLUMN inventory_count INTEGER DEFAULT 5;
  ALTER TABLE fruits ADD CONSTRAINT name CHECK (name IN ('apple', 'banana', 'orange'));
  SELECT name, color, inventory_count FROM fruits;
  RELEASE SAVEPOINT cockroach_restart;
  COMMIT;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants