Skip to content

Add support for chr(0) #17128

@pepijnve

Description

@pepijnve

Is your feature request related to a problem or challenge?

The current implementation of chr explicitly rejects the null character. There's a comment in the code stating that "chr(0) is disallowed because text data types cannot store that character". As far as I can tell, Rust has no issue with this, nor do Arrow UTF-8 arrays.

A quick check with SQLite shows that it is allowed there, but (not entirely unexpected) ends up truncating the string when it is printed. Converting to hexadecimal does show that the complete string is retained and can be processed fine by SQLite.

sqlite> select hex('A' || char(0) || 'Z');
41005A
sqlite> select 'A' || char(0) || 'Z';
A

DuckDB also allows the null character and does better when printing.

D select chr(0);
┌─────────┐
│ chr(0)  │
│ varchar │
├─────────┤
│ \0      │
└─────────┘

Describe the solution you'd like

Relax the null character restriction in the chr implementation.

Describe alternatives you've considered

N/A

Additional context

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions