在 pgadmin iii 中导入 .sql 文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22217642/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:16:19  来源:igfitidea点击:

Import .sql file in pgadmin iii

sqlpostgresqlpgadmin

提问by user1954209

I want to import a sql file in PostgreSQL. I am using pgadmin iii. I create an sql file in phpmyadmin and now i want to import same file in pgadmin iii. I am doing following but it didn't work for me. I select schema of the database in pgadmin iii and after that I try to execute following query:

我想在 PostgreSQL 中导入一个 sql 文件。我正在使用 pgadmin iii。我在 phpmyadmin 中创建了一个 sql 文件,现在我想在 pgadmin iii 中导入相同的文件。我正在关注,但它对我不起作用。我在 pgadmin iii 中选择数据库的架构,然后我尝试执行以下查询:

\i C:/Users/umair/Downloads/school_management_system(1).sql

but it generates an error and the error is:

但它会产生一个错误,错误是:

ERROR:  syntax error at or near "\"
LINE 1: \i C:/Users/umair/Downloads/school_management_system(1).sql
        ^
********** Error **********

ERROR: syntax error at or near "\"
SQL state: 42601
Character: 1

Please help me out.

请帮帮我。

回答by Houari

I think that the best way to import an sql file is using the psqltool like this:

我认为导入 sql 文件的最佳方法是使用这样的psql工具:

psql -U postgres -h localhost -d my_database -f "C:/Users/umair/Downloads/school_management_system(1).sql"

回答by DrColossos

You cannot import a plain *sql file via pgAdmin. It only supports the custom import as created via (pg_restore- that pgAdmin uses in the background).

您不能通过 pgAdmin 导入普通的 *sql 文件。它仅支持通过(pg_restore- pgAdmin 在后台使用)创建的自定义导入。

You should use the command line, NOT pgAdmin for this task. Your comment to another answer suggests that you executed the command from pgAdmin. This will not work.

对于此任务,您应该使用命令行,而不是 pgAdmin。您对另一个答案的评论表明您从 pgAdmin 执行了该命令。这是行不通的。

psql -U username -h localhost -d database_name < path/to/your/file.sql

Note that -h is optional and it depends on how you connect to the system.

请注意,-h 是可选的,它取决于您如何连接到系统。

回答by Cathy Graichen

On Windows, I can only run the psql command from a regular CMD console window, not from a bash window like I might get if I have git installed. You should have psql.exe somewhere like C:\Program Files\PostgreSQL\9.4\bin.

在 Windows 上,我只能从常规 CMD 控制台窗口运行 psql 命令,而不能从 bash 窗口运行,就像我安装了 git 一样。你应该在 C:\Program Files\PostgreSQL\9.4\bin 之类的地方有 psql.exe。

回答by Ahmed Aboud

if you are on windows use the pgsql Shell enter your server and database and user information then run without any quotes

如果您使用的是 Windows,请使用 pgsql Shell 输入您的服务器和数据库以及用户信息,然后在不带任何引号的情况下运行

\i D:/folder/your_table.sql

回答by GabeMeister

@DrColossos is correct. You have to use that command from the command line in the directory that contains the psql.exe executable.

@DrColossos 是正确的。您必须从包含 psql.exe 可执行文件的目录中的命令行使用该命令。

Keep in mind if you are using this command to replace a database already on your system, then you have to delete that database before you run the command.

请记住,如果您使用此命令替换系统上已有的数据库,则必须在运行该命令之前删除该数据库。

If you get weird indexing issues after you run the command please see this tutorialon how to fix it.

如果您在运行命令后遇到奇怪的索引问题,请参阅本教程了解如何修复它。