[英]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.