Presto: Cannot escape '_' (underscore) in like statement.

Created on 16 Apr 2014  路  8Comments  路  Source: prestodb/presto

Escaping the underscore in a like statement results in no records being matched.

Example:
select * from mytable where category like '%\_common';

Will not match any results. Without the \, it will match _uncommon.

Escaping doesn't appear to be working properly.

Most helpful comment

All 8 comments

Presto follows ANSI SQL for the LIKE operator: you must specify the escape character using the ESCAPE clause. There is no default as in some other databases.

'abc' LIKE 'a\_c' ESCAPE '\'

How can I input a quote? I try ' ' to escape, but failed.

select '\'' ESCAPE '\' from test

@hellopower in standard SQL, single quotes are escaped by doubling them: SELECT 'it''s great'

Why is there no documentation within presto's SQL doc about LIKE?
This page mentions it, but that's it. https://prestodb.io/docs/current/functions/regexp.html
Can this comment be moved to a new issue?

It's been 2.5 years plus and no movement on documenting LIKE and the wildcards it uses...

@oaustegard do you want to submit a PR?

Was this page helpful?
0 / 5 - 0 ratings