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

时间:2021-04-24 15:42:46

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?

导致此错误的原因是什么?

3 个解决方案

#1


31  

I've installed phpPgAdmin to try to reproduce your error. I got it right away when tried to create a test table:

我已经安装了phpPgAdmin来尝试重现你的错误。我试图创建一个测试表时立即得到它:

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

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(*)总计来自(...)。我发现只有当查询页面上的复选框“Paginate results”设置为on时才会发生这种情况(显然phpPgAdmin会尝试计算它将获得多少行,然后逐页显示)。取消选中它,您的查询将正常工作:

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

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禁用更多输出

#2


0  

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用户界面提供了两个用于运行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

屏幕

#3


0  

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

#1


31  

I've installed phpPgAdmin to try to reproduce your error. I got it right away when tried to create a test table:

我已经安装了phpPgAdmin来尝试重现你的错误。我试图创建一个测试表时立即得到它:

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

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(*)总计来自(...)。我发现只有当查询页面上的复选框“Paginate results”设置为on时才会发生这种情况(显然phpPgAdmin会尝试计算它将获得多少行,然后逐页显示)。取消选中它,您的查询将正常工作:

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

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禁用更多输出

#2


0  

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用户界面提供了两个用于运行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

屏幕

#3


0  

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