2016-08-01 59 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