cockroachdb / cockroachdb/cockroach

TEXT columns with NUL byte are silently truncated

Open
#167,287 1 comment 0 reactions 0 assignees View on GitHub
C-bug O-community T-sql-foundations
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

PostgreSQL:

=# select E'a\x00b';
ERROR: invalid byte sequence for encoding "UTF8": 0x00

=# select E'a\xffb';
ERROR: invalid byte sequence for encoding "UTF8": 0xff

CockroachDB:

(1)=> select E'a\x00b';
?column?
──────────
a

(1)=> select E'a\xffb';
ERROR: lexical error: invalid UTF-8 byte sequence
DETAIL: source SQL:
select E'a\xffb';
^

This is especially a problem when retrieving values from a table, which are silently truncates. The length() is correct though, and it works when converting to bytea:

=> create table tbl (t text);
=> insert into tbl values (E'a\x00b');

=> select t, length(t), t::bytea from tbl;
t │ length │ t
───┼────────┼──────────
a │ 3 │ \x610062

CockroachDB CCL v26.1.1 (x86_64-pc-linux-gnu, built 2026/03/04 12:08:22, go1.25.5)

Related old issue: #9059

Jira issue: CRDB-62369

Epic CRDB-60814

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.