Postgresql insert multiple rows - crash

I am using PostgreSQL 8.1.11.

And I'm going crazy. Why can't I use the underlying SQL statement as an INSERT?

I provide:

INSERT INTO the_leads_details ( id, lead_id, question_id, i_value, c_value ) VALUES
( 1, 1, 1, NULL, '4500' ), ( 2, 1, 2,    1, NULL );

                         ^ this comma is a problem

What am I missing? This is similar to the basic SQL INSERT statement for inserting multiple rows. Is my problem related to my version of PostgreSQL?

I insert a lot of rows and I try to optimize multiple INSERT lines instead of placing multiple INSERTs.

+5
source share
4 answers

Multi-line INSERT syntax is not supported in PostgreSQL 8.1, you need to upgrade to version 8.2 or later (and if you upgrade today, you really need to upgrade to 8.4, not 8.2!)

, , , 8.1 , .

+14

, Postgresl 8.1 VALUES. :

INSERT INTO table [ ( column [, ...] ) ]
    { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) | query }

http://www.postgresql.org/docs/8.1/static/sql-insert.html

+4

I know this is an old thread, but this will work:

INSERT INTO the_leads_details ( id, lead_id, question_id, i_value, c_value ) (
SELECT 1, 1, 1, NULL, '4500' 
UNION SELECT 2, 1, 2,    1, NULL 
);
+2
source

The syntax is correct, are you sure the problem is a comma?

+1
source

All Articles