2016-08-01 70 views
4

,所以我試圖運行一個腳本這樣一個單引號:PostgreSQL的逃避where子句

select id 
from owner 
where owner.name = "john's" 

,我收到此錯誤:ERROR: column "john's" does not exist

而且我想是這樣的:where owner.name = 'john\'s',但它DIT不行

任何人都知道我怎麼可以運行這樣一個查詢?

+1

嘗試雙單引號= 「約翰的'」? – JamieD77

+1

[在PostgreSQL中用單引號插入文本]可能重複(http://stackoverflow.com/questions/12316953/insert-text-with-single-quotes-in-postgresql) – JNevill

+0

'e'john \'s''應該做的伎倆。 (e前綴允許在字符串文字中使用c樣式反斜槓引號(以及其他內容)) – joop

回答

4

當你將它們加倍時,你可以逃脫單引號。 例如:

= 'john''s' 
2

試試這個

select id 
from owner 
where owner.name = (E'john\'s')::text