Skip to content

Commit 6b2b12c

Browse files
committed
Add collation to constant comparisons
This PR adds `C` collation to generated constant comparison pushdowns. This allows to avoid the problem with collation sensitive comparison when the `LIKE` operator is transformed to comparison by the optimizer. Fixes: #364 Fixes: #462
1 parent a274248 commit 6b2b12c

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/postgres_filter_pushdown.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ string PostgresFilterPushdown::TransformConstantFilter(string &column_name, Cons
7676
constant_string = TransformLiteral(constant_filter.constant);
7777
}
7878
auto operator_string = TransformComparison(constant_filter.comparison_type);
79-
return StringUtil::Format("%s %s %s", column_name, operator_string, constant_string);
79+
string comparison = StringUtil::Format("%s %s %s", column_name, operator_string, constant_string);
80+
if (constant_filter.constant.type().id() == LogicalTypeId::VARCHAR) {
81+
comparison += " COLLATE \"C\"";
82+
}
83+
return comparison;
8084
}
8185

8286
string PostgresFilterPushdown::TransformFilter(string &column_name, TableFilter &filter, column_t column_id) {

test/sql/storage/attach_like.test

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# name: test/sql/storage/attach_like.test
2+
# description: Test LIKE statement
3+
# group: [storage]
4+
5+
require postgres_scanner
6+
7+
require-env POSTGRES_TEST_DATABASE_AVAILABLE
8+
9+
statement ok
10+
PRAGMA enable_verification
11+
12+
statement ok
13+
ATTACH 'dbname=postgresscanner' AS s1 (TYPE POSTGRES)
14+
15+
statement ok
16+
USE s1
17+
18+
statement ok
19+
CREATE OR REPLACE TABLE like_test (col1 VARCHAR)
20+
21+
statement ok
22+
INSERT INTO like_test VALUES ('foo8bar'),('foo9bar'),('Здра9вейте')
23+
24+
query I
25+
FROM like_test WHERE col1 LIKE 'foo8%';
26+
----
27+
foo8bar
28+
29+
query I
30+
FROM like_test WHERE col1 LIKE 'foo9%';
31+
----
32+
foo9bar
33+
34+
query I
35+
FROM like_test WHERE col1 LIKE 'Здра%';
36+
----
37+
Здра9вейте
38+
39+
query I
40+
FROM like_test WHERE col1 LIKE 'Здра9%';
41+
----
42+
Здра9вейте
43+
44+
statement ok
45+
DROP TABLE like_test
46+
47+
statement ok
48+
USE memory
49+
50+
statement ok
51+
DETACH s1

0 commit comments

Comments
 (0)