-1

I need to search in my column strings which contains '

select * from app_user au where au.last_name like '%'%'

but something like that gives me

SQL Error [42601]: Unterminated string literal started at position 55

I tried also '%\'%', but it's not working too, how to escape ' in postgres?

1

2 Answers 2

0

To escape ', you need to add it twice. Use '' to resolve it.

select * from app_user au where au.last_name like '%''%'
Sign up to request clarification or add additional context in comments.

1 Comment

@nbk the game ?
0

You need to double the single quote to get the result

CREATE TABLE app_user (last_name text)
INSERT INTO app_user VALUES ('ma''affee')
select * from app_user au where au.last_name like '%''%'
last_name
ma'affee

fiddle

As you see in the sample the INSERT needs also a double single quote, but prepare statements with parameters will take the need to double single quote away when inserting or selecting

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.