GoogleCloudPlatform / pgadapter

PostgreSQL wire-protocol proxy for Cloud Spanner
https://cloud.google.com/spanner/docs/postgresql-interface#postgresql-client-support
Apache License 2.0
54 stars 20 forks source link

Like with an escape clause fails #1386

Open olavloite opened 7 months ago

olavloite commented 7 months ago
ERROR: Postgres function like_escape(text, text) is not supported - Statement: 'select s1_0.id,s1_0.active,s1_0.created_at,s1_0.first_name,s1_0.full_name,s1_0.last_name,s1_0.updated_at from singers s1_0 where s1_0.last_name like $1 escape '\''
amuware commented 2 months ago

Hello, we are facing the same issue: @Query("SELECT r FROM DNSRecordEntity r WHERE LOWER(r.name) LIKE LOWER(?1) OR LOWER(r.irn) LIKE LOWER(?1)")

{"code":"500","message":"JDBC exception executing SQL ...ERROR: Postgres function like_escape(text, text) is not supported - Statement: 'select ... from ttdev de1_0 where lower(de1_0.name) like lower($1) escape '' or lower(de1_0.xx) like lower($2) escape '''] [n\/a]","status":"Internal Server Error"}

is there any solution ? Thanks

olavloite commented 2 months ago

It depends a bit on the use case. One possible option could be to use the starts_with function like in this example: https://github.com/GoogleCloudPlatform/pgadapter/blob/05a09bcad9dd51b40207e0f56bc0aace3f7f8e7f/samples/java/spring-data-jpa/src/main/java/com/google/cloud/spanner/pgadapter/sample/repository/SingerRepository.java#L26

If that is not an option in your case, then I can have a look at adding a query replacement in PGAdapter. We already replace some known function calls and statements, so this could be added to that.