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');