Skip to content

sql: DDL after write error is misleading #57476

@jayshrivastava

Description

@jayshrivastava

The following error is misleading:

root@localhost:26257/defaultdb> create table foo (i int, j int);
CREATE TABLE

root@localhost:26257/defaultdb> begin;
BEGIN

root@localhost:26257/defaultdb  OPEN> insert into foo values (1,2);
INSERT 1

root@localhost:26257/defaultdb  OPEN>  create table t();
ERROR: unimplemented: schema change statement cannot follow a statement that has written in the same transaction
SQLSTATE: 0A000
HINT: You have attempted to use a feature that is not yet implemented.
See: https://go.crdb.dev/issue-v/26508/v21.1

Although it says "schema change statement cannot follow a statement that has written in the same transaction", one can successfully preform a schema change after a write in a txn:

root@localhost:26257/defaultdb  OPEN> create table foo (i int, j int);
CREATE TABLE

root@localhost:26257/defaultdb  OPEN> create table bar (j int);
CREATE TABLE

root@localhost:26257/defaultdb> begin;
BEGIN

root@localhost:26257/defaultdb  OPEN> alter table bar drop column j;
ALTER TABLE

root@localhost:26257/defaultdb  OPEN> insert into foo values (1,2);
INSERT 1

root@localhost:26257/defaultdb  OPEN> create table t();
CREATE TABLE

root@localhost:26257/defaultdb  OPEN> commit;
COMMIT

The error message should be updated to say that we do not support DDLs if the first write in a txn precedes the first DDL. h in the txn

This issue relates to #54477.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions