• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

132
Views
LIKE clause with \ character in PostgreSQL

I have this behavior in PostgreSQL 9.3:

-- (1) this "doesn't" work
select 't\om' like '%t\om%'
-- result = false

-- (2) this works
select 't/om' like '%t/om%'
-- result = true

Why is the (1) query result false? What is the best way to get true in (1) query?

about 3 years ago · Santiago Trujillo
2 answers
Answer question

0

The \ has no special meaning in SQL except inside the condition for the LIKE operator where it can be used to escape the wildcard characters.

But you can define a different escape character for LIKE which then makes the \ a "normal" character:

select 't\om' like '%t\om%' escape '#';

edit

As Sunrelax has commented, you can also use an empty string as the "escape" sequence:

select 't\om' like '%t\om%' escape '';
about 3 years ago · Santiago Trujillo Report

0

\ is an escape sequence, so you need to escape it, too:

select 't\om' like '%t\\om%';

There is also a configuration option you can set. See Escaping backslash in Postgresql

about 3 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error