cockroachdb / cockroachdb/cockroach

Unexpected error when insert a collatedstring{es}[] value into column with type string[]

Open
#152,659 1 comment 0 reactions 0 assignees View on GitHub
A-sql-typing C-bug O-community T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

**Describe the problem**

Please describe the issue you observed, and any steps we can take to reproduce it:

**To Reproduce**

What did you do? Describe in your own words.

When I insert a collatedstring{es}[] value into column with type string[], I meet an unexpected error:

```
CREATE TABLE t1 (c1 STRING[]);
INSERT INTO t1 (c1) VALUES(ARRAY[('' COLLATE es)]), (ARRAY['']);

ERROR: VALUES types string[] and collatedstring{es}[] cannot be matched
SQLSTATE: 42804
```

However, if I do this with prepared statement, it will be executed successfully.
```
CREATE TABLE t1 (c1 STRING[]);
-- INSERT INTO t1 (c1) VALUES(ARRAY[('' COLLATE es)]), (ARRAY['']);
PREPARE prepare_query (string[], string[]) AS INSERT INTO t1 (c1) VALUES($1), ($2);
EXECUTE prepare_query(ARRAY[('' COLLATE es)], ARRAY['']);
DEALLOCATE prepare_query;
SELECT * FROM t1;
c1
"{""""}"
"{""""}"
```

**Expected behavior**
A clear and concise description of what you expected to happen.

The normal query should be consistent with the prepared statement.

**Additional data / screenshots**
If the problem is SQL-related, include a copy of the SQL query and the schema
of the supporting tables.

If a node in your cluster encountered a fatal error, supply the contents of the
log directories (at minimum of the affected node(s), but preferably all nodes).

Note that log files can contain confidential information. Please continue
creating this issue, but contact support@cockroachlabs.com to submit the log
files in private.

If applicable, add screenshots to help explain your problem.

**Environment:**
- CockroachDB version [CockroachDB CCL v25.1.6 (x86_64-pc-linux-gnu, built 2025/05/09 15:48:03, go1.22.8 X:nocoverageredesign)]
- Server OS: [Ubuntu 24.04]
- Client app [`cockroach sql`, JDBC]

**Additional context**
What was the impact?

Add any other context about the problem here.

Jira issue: CRDB-53966

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.