简体   繁体   English

SQL导入PostgreSQL 8.4.20失败并显示语法错误

[英]SQL import into PostgreSQL 8.4.20 fails with syntax error

I exported SQL file with data from existing Mysql database. 我使用现有Mysql数据库中的数据导出了SQL文件。 Now I am trying to import it in PostgrSQL database. 现在,我试图将其导入PostgrSQL数据库中。

I tried to use phpPgAdmin import field. 我尝试使用phpPgAdmin导入字段。 I executed this SQL because I have already created my tables. 我执行此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);

Error: 错误:

SQL error: SQL错误:

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

I checked SQL validity here and there was no errors found. 在这里检查了SQL的有效性,没有发现错误。 I don't understand where is the issue ? 我不明白问题出在哪里?

Maybe PostgreSQL version problems? 也许PostgreSQL版本有问题吗?

Based on your suggestions I changed my code to : 根据您的建议,我将代码更改为:

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

Still the same error. 还是一样的错误。

Thanks. 谢谢。

Character literals need to be enclosed in single quotes, not double quotes. 字符文字需要用单引号而不是双引号引起来。 Double quotes are for identifiers. 双引号用于标识符。 "Treileri" is an identifier (eg a column name), 'Treileri' is a character literal. "Treileri"是标识符(例如列名), 'Treileri'是字符文字。

So you need to replace all double quotes for the values with single quotes: 因此,您需要将所有双引号替换为单引号:

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),
.....

More details about identifiers and literals can be found in the manual: 可以在手册中找到有关标识符和文字的更多详细信息:

Working SQLFiddle example: http://sqlfiddle.com/#!15/87c23/1 正常的SQLFiddle示例: http ://sqlfiddle.com/#!15/87c23/1


If this is a new installation you should not use a version that is no longer maintained (=supported). 如果这是新安装,则不应使用不再维护(=受支持)的版本。 8.4 is really old. 8.4真的很老。 For a new installation you should go for 9.3 or 9.4 对于新安装,您应该使用9.3或9.4

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

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