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
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
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屋!
查看全文