Skip to content

Commit 8c4cb00

Browse files
Merge pull request ClickHouse#70439 from ClickHouse/backport/24.8/69584
Backport ClickHouse#69584 to 24.8: Fix inserting into FixedString column in PostgreSQL engine
2 parents a5bf9e8 + 462c2cc commit 8c4cb00

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/Core/PostgreSQL/insertPostgreSQLValue.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#if USE_LIBPQXX
44
#include <Columns/ColumnNullable.h>
55
#include <Columns/ColumnString.h>
6+
#include <Columns/ColumnFixedString.h>
67
#include <Columns/ColumnArray.h>
78
#include <Columns/ColumnsNumber.h>
89
#include <Columns/ColumnDecimal.h>
@@ -82,6 +83,8 @@ void insertPostgreSQLValue(
8283
case ExternalResultDescription::ValueType::vtEnum8:
8384
case ExternalResultDescription::ValueType::vtEnum16:
8485
case ExternalResultDescription::ValueType::vtFixedString:
86+
assert_cast<ColumnFixedString &>(column).insertData(value.data(), value.size());
87+
break;
8588
case ExternalResultDescription::ValueType::vtString:
8689
assert_cast<ColumnString &>(column).insertData(value.data(), value.size());
8790
break;

tests/integration/test_storage_postgresql/test.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,7 @@ def test_postgres_distributed(started_cluster):
526526
result = node2.query("SELECT DISTINCT(name) FROM test_shards ORDER BY name")
527527
started_cluster.unpause_container("postgres1")
528528
assert result == "host2\nhost4\n" or result == "host3\nhost4\n"
529+
node2.query("DROP TABLE test_shards2")
529530
node2.query("DROP TABLE test_shards")
530531
node2.query("DROP TABLE test_replicas")
531532

@@ -817,6 +818,9 @@ def test_auto_close_connection(started_cluster):
817818
# Connection from python + pg_stat table also has a connection at the moment of current query
818819
assert count == 2
819820

821+
node2.query("DROP TABLE test.stat")
822+
node2.query("DROP TABLE test.test_table")
823+
820824

821825
def test_literal_escaping(started_cluster):
822826
cursor = started_cluster.postgres_conn.cursor()
@@ -832,6 +836,7 @@ def test_literal_escaping(started_cluster):
832836
node1.query("SELECT * FROM escaping WHERE text like '%a''a%'") # %a'a% -> %a''a%
833837
node1.query("SELECT * FROM escaping WHERE text like '%a\\'a%'") # %a'a% -> %a''a%
834838
cursor.execute(f"DROP TABLE escaping")
839+
node1.query("DROP TABLE default.escaping")
835840

836841

837842
def test_filter_pushdown(started_cluster):
@@ -886,6 +891,28 @@ def compare_results(query, **kwargs):
886891
)
887892

888893
cursor.execute("DROP SCHEMA test_filter_pushdown CASCADE")
894+
node1.query("DROP TABLE test_filter_pushdown_local_table")
895+
node1.query("DROP TABLE test_filter_pushdown_pg_table")
896+
897+
898+
def test_fixed_string_type(started_cluster):
899+
cursor = started_cluster.postgres_conn.cursor()
900+
cursor.execute("DROP TABLE IF EXISTS test_fixed_string")
901+
cursor.execute(
902+
"CREATE TABLE test_fixed_string (contact_id numeric NULL, email varchar NULL)"
903+
)
904+
cursor.execute("INSERT INTO test_fixed_string values (1, 'abc')")
905+
906+
node1.query("DROP TABLE IF EXISTS test_fixed_string")
907+
node1.query(
908+
"CREATE TABLE test_fixed_string(contact_id Int64, email Nullable(FixedString(3))) ENGINE = PostgreSQL('postgres1:5432', 'postgres', 'test_fixed_string', 'postgres', 'mysecretpassword')"
909+
)
910+
911+
result = node1.query("SELECT * FROM test_fixed_string format TSV")
912+
913+
assert result.strip() == "1\tabc"
914+
915+
node1.query("DROP TABLE test_fixed_string")
889916

890917

891918
if __name__ == "__main__":

0 commit comments

Comments
 (0)