2017-05-26 6 views
0

varcharにLIKEオプションを使用して'が含まれている場合に検索します。テキストで「 '」を検索するPostgres

私はそれが

select * 
from table 
where field like '%'%' 

が、少し違うようなものだと思います。

+0

'select * from table where $ thing $% '$ $ thing $'?.. –

答えて

3

単一引用符をエスケープについて答える:

ドル引用符記号を使用することができます。

select * from table where field like $thing$%'%$thing$; 

または引用符の前にEを使用します。

select * from table where field like e'%\'%' 

または2つの単一引用符:

select * from table where field like '%''%' 

https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html

+1

最初の2つの解決策は非標準SQLであり、Postgresにのみ適用されることに注意してください。 –

+0

申し訳ありません - 私は他のタグに気付かなかった。私の悪い –

関連する問題