Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect query results in PostgreSQL connector when comparing varchar values are collation sensitive #3645

Closed
findepi opened this issue May 6, 2020 · 6 comments
Labels
bug Something isn't working correctness
Milestone

Comments

@findepi
Copy link
Member

findepi commented May 6, 2020

Using io.prestosql.plugin.postgresql.PostgreSqlQueryRunner#main PostgreSQL connector:

trino:public> SELECT count(*) FROM orders WHERE orderpriority BETWEEN '5-' AND '5.' OR rand() = 42;
 _col0
-------
  2950
trino:public> SELECT count(*) FROM orders WHERE orderpriority BETWEEN '5-' AND '5.';
 _col0
-------
     0

And:

trino:public> select count(*) from test_collation where a > 'Ala' OR rand() = 42;
 _col0
-------
     1
trino:public> select count(*) from test_collation where a > 'Ala';;
 _col0
-------
     0

This is because default collation in Postgres:

  • puts 5. after 5- (like Trino), but before 5-LOW (the actual value in the column).
  • puts a before A, unlike Trino
@findepi findepi added the bug Something isn't working label May 6, 2020
@findepi
Copy link
Member Author

findepi commented May 6, 2020

in Postgres the recommended way is to use COLLATE "C" like here:

SELECT count(*) FROM orders WHERE orderpriority COLLATE "C" BETWEEN '5-' AND '5.';

@findepi
Copy link
Member Author

findepi commented May 8, 2020

@kokosing
Copy link
Member

I think this issue is more generic. It not only about punctuation symbol. PostgreSQL has different collation by default than Trino. For example for PostgreSQL 'a' < 'A' while in Trino 'A' < 'a'

@kokosing kokosing changed the title Incorrect query results in PostgreSQL connector when comparing varchar values with punctuation symbols Incorrect query results in PostgreSQL connector when comparing varchar values are collation sensitive Feb 17, 2021
@findepi
Copy link
Member Author

findepi commented Feb 17, 2021

Thanks for broadening the issue scope. Can you please add relevant examples to the description as well?

@kokosing
Copy link
Member

Sure, done.

@findepi
Copy link
Member Author

findepi commented Mar 5, 2021

#7145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctness
Development

No branches or pull requests

2 participants