Skip to content

Unable to rename database if a table exists that references a sequence #45411

@florence-crl

Description

@florence-crl

Describe the problem
You can not rename a database if a table references a sequence. The error message is not accurate.

To Reproduce
with cockroach sql

defaultdb> CREATE DATABASE db1;
defaultdb> USE db1;
db1> CREATE SEQUENCE seq1 MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1;
db1> CREATE TABLE tab1 (
  id INT8 NOT NULL DEFAULT nextval('seq1':::STRING),
  name STRING NULL,
  CONSTRAINT "primary" PRIMARY KEY (id ASC),
  FAMILY "primary" (id, name)
);
root@localhost:26257/db1> use defaultdb;
root@localhost:26257/defaultdb> alter database db1 rename to db2;
pq: cannot rename database because view "tab1" depends on table "seq1"
HINT: you can drop tab1 instead.

In error message , view "tab1" is actually a table and table "seq1" is actually a sequence.

Expected behavior
I expect the database to be renamed without error.

Additional data / screenshots
The error is generated by cockroach/pkg/sql/rename_database.go which has the comment below so it is intended for views.

    // Check if any views depend on tables in the database. Because our views
    // are currently just stored as strings, they explicitly specify the database
    // name. Rather than trying to rewrite them with the changed DB name, we
    // simply disallow such renames for now

Environment:

  • CockroachDB version: 19.2.4
  • Server OS: Linux
  • Client app: cockroach sql

Additional context
What was the impact?
The customer is not able to rename their database without dropping the table that uses a sequence.

I am not sure if this issue is the same as #34416

Metadata

Metadata

Assignees

Labels

A-schema-changesA-sql-sequencesSequence handling in SQLC-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.O-communityOriginated from the community

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions