简体   繁体   English

来自phpPgAdmin的Postgres SQL插入查询语法错误

[英]Postgres sql insert query syntax error from phpPgAdmin

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? 是什么导致此错误?

I've installed phpPgAdmin to try to reproduce your error. 我已安装phpPgAdmin尝试重现您的错误。 I got it right away when tried to create a test table: 尝试创建测试表时,我马上就知道了:

在此处输入图片说明

So looks like phpPgAdmin wraping your query into select count(*) as total from (...) . 所以看起来phpPgAdmin将您的查询包装为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). 我发现只有在查询页面上的“分页结果”复选框设置为on时,它才会发生(显然phpPgAdmin试图计算它将获得多少行,然后逐页显示)。 Uncheck it and your query will work fine: 取消选中它,您的查询将正常运行:

在此处输入图片说明

updated 1 更新1

Similar question - INSERT INTO PostgreSQL 类似的问题- 插入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禁用更多输出

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: 简而言之:

screen 屏幕

你也可以尝试

INSERT INTO "user" ("username", "password_hash", "first_name", "last_name") VALUES( 'Foo',MD5('54321'),'Foo','Bar' );

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

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