SQL导入PostgreSQL 8.4.20失败,语法错误

时间:2015-02-01 20:13:08

标签: mysql sql postgresql

我使用现有Mysql数据库中的数据导出SQL文件。现在我试图在PostgrSQL数据库中导入它。

我尝试使用phpPgAdmin导入字段。我执行了这个SQL,因为我已经创建了我的表。

INSERT INTO `categories` (`id`, `name`, `created_at`, `updated_at`, `ancestry`, `ancestry_depth`, `priority`) VALUES
(1, 'Treileri', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(2, 'Kravas automašīnas', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(3, 'Teleskopiskie iekrāvēji', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(4, 'Ekskavatori', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(5, 'Iekrāvēji', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(6, 'Pacēlāji', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(7, 'Elektroiekārtas', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(8, 'Ģeneratori', '2014-09-24 17:45:02', '2014-09-24 17:45:02', '7', 1, NULL),
(9, 'Strāvas kārbas', '2014-09-24 17:45:02', '2014-09-24 17:45:02', '7', 1, NULL),
(10, 'Aprīkojums', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(11, 'Vibro blietes', '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(12, 'Ūdens pumpji', '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(13, 'Vinčas', '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(14, 'Gāzes sildītāji', '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(15, 'Plātņu satvērēji', '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(16, 'Celtniecības sastatnes', '2014-09-24 17:45:03', '2014-09-24 17:45:03', NULL, 0, NULL),
(17, 'Citi', '2014-09-24 17:45:03', '2014-09-24 17:45:03', NULL, 0, NULL);

错误:

SQL错误:

ERROR:  syntax error at or near "INTO"
LINE 1: SELECT COUNT(*) AS total FROM (INSERT INTO `categories` (`id...
                                              ^

我检查了SQL有效性here,但未发现任何错误。我不明白问题出在哪里?

也许是PostgreSQL版本的问题?

根据您的建议,我将代码更改为:

INSERT INTO "categories" ("id", "name", "created_at", "updated_at", "ancestry", "ancestry_depth", "priority") VALUES
(1, "Treileri", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(2, "Kravas automašīnas", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(3, "Teleskopiskie iekrāvēji", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(4, "Ekskavatori", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(5, "Iekrāvēji", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(6, "Pacēlāji", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(7, "Elektroiekārtas", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(8, "Ģeneratori", '2014-09-24 17:45:02', '2014-09-24 17:45:02', '7', 1, NULL),
(9, "Strāvas kārbas", '2014-09-24 17:45:02', '2014-09-24 17:45:02', '7', 1, NULL),
(10, "Aprīkojums", '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(11, "Vibro blietes", '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(12, "Ūdens pumpji", '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(13, "Vinčas", '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(14, "Gāzes sildītāji", '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(15, "Plātņu satvērēji", '2014-09-24 17:45:03', '2014-09-24 17:45:03', '10', 1, NULL),
(16, "Celtniecības sastatnes", '2014-09-24 17:45:03', '2014-09-24 17:45:03', NULL, 0, NULL),
(17, "Citi", '2014-09-24 17:45:03', '2014-09-24 17:45:03', NULL, 0, NULL);

仍然是同样的错误。

感谢。

1 个答案:

答案 0 :(得分:0)

字符文字需要用单引号括起来,而不是双引号。双引号用于标识符。 "Treileri"是标识符(例如列名),'Treileri'是字符文字。

因此,您需要使用单引号替换值的所有双引号:

INSERT INTO "categories" ("id", "name", "created_at", "updated_at", "ancestry", "ancestry_depth", "priority") VALUES
(1, 'Treileri', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
(2, 'Kravas automašīnas', '2014-09-24 17:45:02', '2014-09-24 17:45:02', NULL, 0, NULL),
.....

有关标识符和文字的更多详细信息,请参见手册:

使用SQLFiddle示例:http://sqlfiddle.com/#!15/87c23/1


如果这是新安装,则不应使用不再维护的版本(=支持)。 8.4真的很老了。对于新安装,您应该使用9.3或9.4