本文翻译自:Insert text with single quotes in PostgreSQL
I have a table test(id,name)
. 我有一个表test(id,name)
。
I need to insert values like: user's log
, 'my user'
, customer's
. 我需要插入以下值: user's log
, 'my user'
, customer's
。
insert into test values (1,'user's log');
insert into test values (2,''my users'');
insert into test values (3,'customer's');
I am getting an error if I run any of the above statements. 如果我运行以上任何语句,都会收到错误消息。
If there is any method to do this correctly please share. 如果有任何方法可以正确执行此操作,请分享。 I don't want any prepared statements. 我不要任何准备好的陈述。
Is it possible using sql escaping mechanism? 是否可以使用sql转义机制?
#1楼
参考:https://stackoom.com/question/pgCX/在PostgreSQL中插入带单引号的文本
#2楼
According to PostgreSQL documentation (4.1.2.1. String Constants) : 根据PostgreSQL文档(4.1.2.1。字符串常量) :
To include a single-quote character within a string constant, write two
adjacent single quotes, e.g. 'Dianne''s horse'.
See also the standard_conforming_strings parameter, which controls whether escaping with backslashes works. 另请参见standard_conforming_strings参数,该参数控制是否使用反斜杠转义。
#3楼
This is so many worlds of bad, because your question implies that you probably have gaping