ClickHouse / ClickHouse/ClickHouse
Error loading data from PostgreSQL table with array column that contains values with one simple quote
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
Hello,
I'm trying to materialize a PostgreSQL table as a ClickHouse table. I'm using the PostgreSQL table engine for this.
One of the column of the PostgreSQL array table is of type text[] (nullable) and the data comes from user inputs. I come across this corner case when ClickHouse fails to load data from this column when the array contains one string with one `'` simple quote char.
I get the following error :
```
SQL Error [1002] [07000]: std::exception. Code: 1001, type: pqxx::argument_error, e.what() = Null byte in SQL string: {'002079} (version 24.6.2.17 (official build))
```
I imagine that ClickHouse tries to cast to string but fails to find the end of the string as there is no second simple quote.
However the value is valid in PostgreSQL and the simple quote is part of the string value.
**How to reproduce**
* Which ClickHouse server version to use : 24.6.2.17
* `CREATE TABLE` statements for all tables involved :
On the PostgreSQL server, you can create a table to test the behavior :
```sql
-- public.test_array definition
CREATE TABLE test_array (
id int4 NOT NULL,
my_pg_array _text NULL,
CONSTRAINT test_array_pk PRIMARY KEY (id)
);
INSERT INTO test_array (id,my_pg_array) VALUES
(1,'{""}'),
(2,NULL),
(3,'{139641,139642,139643'),
(4,'{}'),
(5,'{''002079}');
```
The id 1 to 4 are different valid exotic PostgreSQL array cases that ClickHouse successfully loads, the id 5 is the one that fails to be loaded by ClickHouse.
In ClickHouse, assuming you configured a PostgreSQL Database Engine, you can test by querying the test table :
```sql
SELECT
id,
my_pg_array,
FROM
pg_db.test_array
```
**Expected behavior**
The string value being correctly de-serialized when loaded into Clickhouse.
Contributor guide
Assessment
This issue has not been assessed yet.