问题描述
将公司数据发现场,导入后发现正则的\"丢"了。其实,是当成转义符了。但是根据下面PG官网提示自PostgreSQL9.1开始默认值就是on,现场肯定是有人主动off了。太坑了~~~
standard_conforming_strings=on,\失去了转义,即''中的字符串保持不变(该是啥是啥)
standard_conforming_strings=off时,\会保留转义的含义,'\'即为''
在Unicode转义语法中,反斜杠后的任何其他字符均按字面意义使用。因此,要包含反斜杠字符,请写两个反斜杠(\\)。如果standard_conforming_strings是off,则反斜杠是字符串文本中的转义字符也可以使用E‘字符’。
实验验证
postgres=# show standard_conforming_strings;
standard_conforming_strings
-----------------------------
on
(1 row)
postgres=# select '\';
?column?
----------
\
(1 row)
postgres=# select '\\';
?column?
----------
\\
(1 row)
postgres=# set standard_conforming_strings=off;
SET
postgres=# show standard_conforming_strings;
standard_conforming_strings
-----------------------------
off
(1 row)
postgres=# select '\\';
WARNING: nonstandard use of \\ in a string literal
LINE 1: select '\\';
^
HINT: Use the escape string syntax for backslashes, e.g., E'\\'.
?column?
----------
\
(1 row)
postgres=# postgres=# select '\';
postgres'#
postgres'# ;
postgres'# ^C
postgres=# select E'\\';
?column?
----------
\
(1 row)
postgres=# select E'\';
postgres'# ;
postgres'# ;
postgres'# ^C
问题处理
1、执行set standard_conforming_strings=on;(只对当前会话有效);
2、再执行插入数据动作即可。