18

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?

Daniel Vérité
  • 58,074
  • 15
  • 129
  • 156
  • 2
    The error message is showing you the error: `SELECT COUNT(*) AS total FROM (INSERT ...` – ypercubeᵀᴹ Aug 21 '13 at 22:36
  • I dont have any clues.... I dont have SELECT COUNT(*) AS total FROM so i dont know where it is taken –  Aug 21 '13 at 22:37
  • 2
    Are all those double-quotes okay in postgresql? The documentation I'm looking at just shows single quotes. And does it need a terminating semicolon? – Hart CO Aug 21 '13 at 22:40
  • 2
    BTW: the strings inside the values need to be in single quotes: `VALUES(123123133,'Eu name','Eu society','Eu notes',true)` – wildplasser Aug 21 '13 at 22:40
  • How are you running the query? Through a GUI or command line interface? Or produced in some other language/framework? – ypercubeᵀᴹ Aug 21 '13 at 22:41
  • Tried with single quotes too, no effect. –  Aug 21 '13 at 22:41
  • Keep the single quotes, it would be the next error when you figure out how that `SELECT COUNT(*)` found its way into the code. – ypercubeᵀᴹ Aug 21 '13 at 22:43
  • i tried in Php postgres admin (ppa) and from code. –  Aug 21 '13 at 22:46
  • Trick #1: introduce a deliberate syntax error at the beginning: `BARF; INSERT INTO users (vk_id, eu_name, eu_society, eu_notes, eu_want_team) VALUES( ... );` The semicolon forces the parser to resync. – wildplasser Aug 21 '13 at 22:58
  • 2
    Well, this could be a bug in phpPgAdmin, I see a report opened in May: [Bugs item #3612602, was opened at 2013-05-03](http://sourceforge.net/mailarchive/message.php?msg_id=30803741) – ypercubeᵀᴹ Aug 21 '13 at 23:06
  • 1
    possible duplicate of [INSERT INTO PostgreSQL](http://stackoverflow.com/questions/18420742/insert-into-postgresql) –  Aug 24 '13 at 19:33

3 Answers3

45

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

enter image description here

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:

enter image description here

updated 1

Similar question - INSERT INTO PostgreSQL

updated 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

Community
  • 1
  • 1
Roman Pekar
  • 107,110
  • 28
  • 195
  • 197
2

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.

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.

However, the one in the menu bar will run data definition queries with no problem.

In short:

screen

0

you could try this as well

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

Bruce Tong
  • 1,366
  • 15
  • 14