postgresql中的字符串文字和转义字符 [英] String literals and escape characters in postgresql
本文介绍了postgresql中的字符串文字和转义字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
尝试将转义字符插入到表中会导致警告。
Attempting to insert an escape character into a table results in a warning.
例如:
create table EscapeTest (text varchar(50));
insert into EscapeTest (text) values ('This is the first part \n And this is the second');
产生警告:
WARNING: nonstandard use of escape in a string literal
(使用PSQL 8.2 )
任何人都知道如何解决这个问题?
Anyone know how to get around this?
推荐答案
部分。文本被插入,但是警告仍然被生成。
Partially. The text is inserted, but the warning is still generated.
我发现一个讨论,表明文本需要在'E'之前,因此:
I found a discussion that indicated the text needed to be preceded with 'E', as such:
insert into EscapeTest (text) values (E'This is the first part \n And this is the second');
这样可以抑制警告,但文本仍未正确返回。当我按照迈克尔的建议添加额外的斜线时,它的工作正常。
This suppressed the warning, but the text was still not being returned correctly. When I added the additional slash as Michael suggested, it worked.
因此:
insert into EscapeTest (text) values (E'This is the first part \\n And this is the second');
这篇关于postgresql中的字符串文字和转义字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文