From 462c2cc55bcc90a356b8790ebe21d23c9c15f35e Mon Sep 17 00:00:00 2001 From: robot-clickhouse Date: Mon, 7 Oct 2024 06:10:51 +0000 Subject: [PATCH] Backport #69584 to 24.8: Fix inserting into FixedString column in PostgreSQL engine --- src/Core/PostgreSQL/insertPostgreSQLValue.cpp | 3 +++ .../test_storage_postgresql/test.py | 27 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/Core/PostgreSQL/insertPostgreSQLValue.cpp b/src/Core/PostgreSQL/insertPostgreSQLValue.cpp index 0ce7222a9a5..559e51f2e70 100644 --- a/src/Core/PostgreSQL/insertPostgreSQLValue.cpp +++ b/src/Core/PostgreSQL/insertPostgreSQLValue.cpp @@ -3,6 +3,7 @@ #if USE_LIBPQXX #include #include +#include #include #include #include @@ -82,6 +83,8 @@ void insertPostgreSQLValue( case ExternalResultDescription::ValueType::vtEnum8: case ExternalResultDescription::ValueType::vtEnum16: case ExternalResultDescription::ValueType::vtFixedString: + assert_cast(column).insertData(value.data(), value.size()); + break; case ExternalResultDescription::ValueType::vtString: assert_cast(column).insertData(value.data(), value.size()); break; diff --git a/tests/integration/test_storage_postgresql/test.py b/tests/integration/test_storage_postgresql/test.py index 12823f1f72d..b1e0bca20ef 100644 --- a/tests/integration/test_storage_postgresql/test.py +++ b/tests/integration/test_storage_postgresql/test.py @@ -526,6 +526,7 @@ def test_postgres_distributed(started_cluster): result = node2.query("SELECT DISTINCT(name) FROM test_shards ORDER BY name") started_cluster.unpause_container("postgres1") assert result == "host2\nhost4\n" or result == "host3\nhost4\n" + node2.query("DROP TABLE test_shards2") node2.query("DROP TABLE test_shards") node2.query("DROP TABLE test_replicas") @@ -817,6 +818,9 @@ def test_auto_close_connection(started_cluster): # Connection from python + pg_stat table also has a connection at the moment of current query assert count == 2 + node2.query("DROP TABLE test.stat") + node2.query("DROP TABLE test.test_table") + def test_literal_escaping(started_cluster): cursor = started_cluster.postgres_conn.cursor() @@ -832,6 +836,7 @@ def test_literal_escaping(started_cluster): node1.query("SELECT * FROM escaping WHERE text like '%a''a%'") # %a'a% -> %a''a% node1.query("SELECT * FROM escaping WHERE text like '%a\\'a%'") # %a'a% -> %a''a% cursor.execute(f"DROP TABLE escaping") + node1.query("DROP TABLE default.escaping") def test_filter_pushdown(started_cluster): @@ -886,6 +891,28 @@ def test_filter_pushdown(started_cluster): ) cursor.execute("DROP SCHEMA test_filter_pushdown CASCADE") + node1.query("DROP TABLE test_filter_pushdown_local_table") + node1.query("DROP TABLE test_filter_pushdown_pg_table") + + +def test_fixed_string_type(started_cluster): + cursor = started_cluster.postgres_conn.cursor() + cursor.execute("DROP TABLE IF EXISTS test_fixed_string") + cursor.execute( + "CREATE TABLE test_fixed_string (contact_id numeric NULL, email varchar NULL)" + ) + cursor.execute("INSERT INTO test_fixed_string values (1, 'abc')") + + node1.query("DROP TABLE IF EXISTS test_fixed_string") + node1.query( + "CREATE TABLE test_fixed_string(contact_id Int64, email Nullable(FixedString(3))) ENGINE = PostgreSQL('postgres1:5432', 'postgres', 'test_fixed_string', 'postgres', 'mysecretpassword')" + ) + + result = node1.query("SELECT * FROM test_fixed_string format TSV") + + assert result.strip() == "1\tabc" + + node1.query("DROP TABLE test_fixed_string") if __name__ == "__main__":