Skip to content

CTAS: mistakenly allowed cross-db type references #105393

@Xiang-Gu

Description

@Xiang-Gu
create database db1;
create type db1.typ as enum('a', 'b', 'c');
create table db1.t (i int primary key, j db1.typ);


create database db2;
create table db2.t as table db1.t; -- Troubling stmt

There are two issues of the last CTAS stmt:

  1. It succeeded even if column j references a user-defined type in another database. We should disallow this because if we were to create this table db2.t manually, we get ERROR: cross database type references are not supported: db1.public.typ.
  2. It succeeded but show create table db2.t gives
 CREATE TABLE public.t (
      i INT8 NULL,
      j db1.public.typ NULL,
      rowid INT8 NOT VISIBLE NOT NULL DEFAULT unique_rowid(),
      CONSTRAINT t_pkey PRIMARY KEY (rowid ASC)
  )

where a new rowid column is inserted as primary key but the original table (db1.t) does not have it and instead has column i as its primary key column.

Jira issue: CRDB-29013

Epic CRDB-27601

Metadata

Metadata

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)v23.1.5

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions