postgresql 来自phpPgAdmin的Postgres sql插入查询语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18368831/
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
Postgres sql insert query syntax error from phpPgAdmin
提问by Roman Pekar
Trying to execute a standard insert query, but it doesn't work.
尝试执行标准插入查询,但不起作用。
INSERT INTO users (vk_id, eu_name, eu_society, eu_notes, eu_want_team)
VALUES ("123123133","Eu name","Eu society","Eu notes","true")
The error I get is the following:
我得到的错误如下:
ERROR: syntax error at or near "INTO" LINE 1: SELECT COUNT(*) AS
total FROM (INSERT INTO users (vk_id, eu_...
What is causing this error?
是什么导致了这个错误?
回答by Roman Pekar
I've installed phpPgAdmin to try to reproduce your error. I got it right away when tried to create a test table:
我已经安装了 phpPgAdmin 来尝试重现您的错误。尝试创建测试表时,我立即得到了它:
So looks like phpPgAdmin wraping your query into select count(*) as total from (...)
. I've found that it happens only when checkbox "Paginate results"on query page is set to on (obviously phpPgAdmin trying to count how many rows it will get and then show it page by page). Uncheck it and your query will work fine:
所以看起来 phpPgAdmin 将您的查询包装到select count(*) as total from (...)
. 我发现它仅在查询页面上的复选框“分页结果”设置为开启时发生(显然 phpPgAdmin 试图计算它将获得多少行,然后逐页显示)。取消选中它,您的查询将正常工作:
updated 1
更新 1
Similar question - INSERT INTO PostgreSQL
类似问题 - INSERT INTO PostgreSQL
updated 2
更新 2
As @akshay mentioned in comments, you also could get similar error running the queries through the command line, see explained situation and answer here - PostgreSQL disable more output
正如@akshay 在评论中提到的,您也可能会遇到类似的错误,通过命令行运行查询,请参阅解释的情况并在此处回答 - PostgreSQL 禁用更多输出
回答by user3393273
The phpPgAdmin UI provides two links for running SQL - one in the main body of the page, and one in the menu bar at the top of the page.
phpPgAdmin UI 提供了两个运行 SQL 的链接——一个在页面主体中,一个在页面顶部的菜单栏中。
The one in the main body of the page will throw the error you're seeing if you run a data definition statement like CREATE TABLE.
如果您运行像 CREATE TABLE 这样的数据定义语句,页面主体中的那个将抛出您看到的错误。
However, the one in the menu bar will run data definition queries with no problem.
但是,菜单栏中的那个将毫无问题地运行数据定义查询。
In short:
简而言之:
回答by Bruce Tong
you could try this as well
你也可以试试这个
INSERT INTO "user" ("username", "password_hash", "first_name", "last_name")
VALUES( 'Foo',MD5('54321'),'Foo','Bar' );
INSERT INTO "user" ("username", "password_hash", "first_name", "last_name")
VALUES( 'Foo',MD5('54321'),'Foo','Bar' );