cockroachdb / cockroachdb/cockroach

import: be more careful with UDT type resolution

Open
#115,842 0 comments 0 reactions 0 assignees View on GitHub
A-import C-bug P-3 T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

Once #115146 merges, the following setup:
```sql
CREATE DATABASE db1;
USE db1;
CREATE TYPE weekday AS ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday');
CREATE DATABASE db2;
USE db2;
CREATE TYPE weekday AS ENUM('Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday');
USE db1;
CREATE TABLE db1_shifts (employee STRING, days weekday[]);
INSERT INTO db1_shifts VALUES ('John', ARRAY['Monday', 'Wednesday', 'Friday']);
INSERT INTO db1_shifts VALUES ('Bob', ARRAY['Tuesday', 'Thursday']);

EXPORT INTO CSV 'nodelocal://1/export1/' FROM SELECT * FROM db1_shifts;

USE db2;
CREATE TABLE db2_shifts (employee STRING, days weekday[]);
IMPORT INTO db2_shifts CSV DATA ('nodelocal://1/export1/export*-n*.0.csv');
SELECT * FROM db2_shifts;
```
will result in us successfully importing the data into `db2_shifts` table.

However, the exported CSV data is of the form:
```
John,"ARRAY['Monday':::db1.public.weekday,'Wednesday':::db1.public.weekday,'Friday':::db1.public.weekday]"
Bob,"ARRAY['Tuesday':::db1.public.weekday,'Thursday':::db1.public.weekday]"
```
Alternatively, we could manually construct CSV data set that uses type casts (and not type hints):
```
John,"ARRAY['Monday'::db1.public.weekday,'Wednesday'::db1.public.weekday,'Friday'::db1.public.weekday]"
Bob,"ARRAY['Tuesday'::db1.public.weekday,'Thursday'::db1.public.weekday]"
```
For both of these CSV data sets, the IMPORT succeeds although it would probably more sense to fail.

Jira issue: CRDB-34242

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.