繁体   English   中英

将MySQL转储导入Postgres并转义\\

[英]import MySQL dump into Postgres and escape \

我收到一个MYSQL转储,需要将其推入Postgres表中。

在poi_dump.sql转储中,有很多插入行。 例子如下:

Insert into table values (1,'hello','\rthis is a beautiful Alan\'s cottage', '\nbyebye')
Insert into table values (1,'hello','\rthis is a big\"Work', '\nbyebye')

我正在使用PSQL命令:

psql analytics < poi_dump.sql

但是,postgres无法识别在''字段中用于转义的所有\\。

Errors From Postgres:
Query buffer reset (cleared).
invalid command \nOn
invalid command \n
invalid command \'
invalid command \'
invalid command \'
invalid command \n
invalid command \"Without
invalid command \nPort-a-loo
Query buffer reset (cleared).
invalid command \n

我怎样才能使postgres在报价字段内接受那些\\ r,\\ n,?

PostgreSQL默认不识别字符串中的反斜杠。 但这行为可以简单地更改:

ides_jmmaj_prac=# select 'hello\nworld';
┌──────────────┐
│   ?column?   │
╞══════════════╡
│ hello\nworld │
└──────────────┘
(1 row)

Time: 0,496 ms
ides_jmmaj_prac=# set standard_conforming_strings TO off;
SET
Time: 0,251 ms
ides_jmmaj_prac=# select 'hello\nworld';
WARNING:  nonstandard use of escape in a string literal
ŘÁDKA 1: select 'hello\nworld';
                ^
DOPORUČENÍ:  Use the escape string syntax for escapes, e.g., E'\r\n'.
┌──────────┐
│ ?column? │
╞══════════╡
│ hello   ↵│
│ world    │
└──────────┘
(1 row)

Time: 0,496 ms

通过以下方式禁用警告:

set escape_string_warning to off;

大概\\r应该被删除。 PostgreSQL使用Unix的结尾-仅\\n (我没有测试过)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM