# How to set escape character in Postgres Like query?

**URL:** <https://discourse.hibernate.org/t/how-to-set-escape-character-in-postgres-like-query/10553>\
**Category:** Hibernate ORM\
**Created:** [October 31, 2024, 10:12pm UTC](https://discourse.hibernate.org/t/how-to-set-escape-character-in-postgres-like-query/10553 "2024-10-31T22:12:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeKeap](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mikekeap/32/3573_2.png) [@MikeKeap](https://discourse.hibernate.org/u/MikeKeap)\
**Post date:** [October 31, 2024, 10:12pm UTC](https://discourse.hibernate.org/t/how-to-set-escape-character-in-postgres-like-query/10553/1 "2024-10-31T22:12:45Z")

</div>

We are using Micronaut Data which appears to use Hibernate 6.4.4. I came across an issue where `escape ''` is appended to a LIKE query that is generated from a repository method. I cannot seem to find how to set that value so our manually-escaped strings pass to postgres as expected. How can I set what value should be in the escape clause without manually writing the query?

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 5, 2024, 3:58pm UTC](https://discourse.hibernate.org/t/how-to-set-escape-character-in-postgres-like-query/10553/2 "2024-11-05T15:58:57Z")

</div>

Sorry, but this is not a Micronaut Data forum. You will have to ask that question elsewhere. When you write the query yourself, you can specify the escape character explicitly.

---

<div class="post-metadata">

**Author:** ![MikeKeap](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/mikekeap/32/3573_2.png) [@MikeKeap](https://discourse.hibernate.org/u/MikeKeap)\
**Post date:** [November 7, 2024, 7:00pm UTC](https://discourse.hibernate.org/t/how-to-set-escape-character-in-postgres-like-query/10553/3 "2024-11-07T19:00:16Z")

</div>

Ah, you are saying the `escape ''` clause is being added by Micronaut, not Hibernate? Thanks!

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [November 11, 2024, 10:10am UTC](https://discourse.hibernate.org/t/how-to-set-escape-character-in-postgres-like-query/10553/4 "2024-11-11T10:10:57Z")

</div>

Hibernate ORM by default has no escape character defined for the `like` pattern, which is according to the SQL specification. To ensure this, when rendering SQL, Hibernate ORM has to emit `escape ''` in the generated SQL on some databases that have a default escape character to implement the specified behavior. So if you want a specific escape character, you have to add that to your HQL `like` predicate.  
I don’t know what Micronaut is doing, I can only tell you how you can use HQL or the JPA Criteria API.
