How do I escape a single quote in Presto?

Viewed 23020

How can I escape a ' (single quote) in Presto?

This is where I am trying to use it

select count(*) as count 
from uploads
where title not in ('Driver's License')

I've tried the usual escapes: , 'Driver\'s License', "Driver's License", E'Driver\'s License' but nothing seems to work. Presto's docs are vague. Anyone know?

3 Answers

Put a single quotes two times in place of single quotes, which you need to escape:

select count(*) as count 
from uploads
where title not in ('Driver''s License')

Use the CHR(39) character function anywhere you need a single quote. Use with either the concat function or using double pipe ||:

select count(*) as count 
from uploads
where title not in (concat('Driver', CHR(39), 's License'))

or

select count(*) as count 
from uploads
where title not in ('Driver' || CHR(39) || 's License')
Related