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