batch insertion - Mailing list pgsql-general

From Korisk
Subject batch insertion
Date
Msg-id 30431377389718@web9e.yandex.ru
Whole thread Raw
Responses Re: batch insertion  (Allan Kamau <kamauallan@gmail.com>)
Re: batch insertion  (Steve Atkins <steve@blighty.com>)
Re: batch insertion  (Adrian Klaver <adrian.klaver@gmail.com>)
Re: batch insertion  (Merlin Moncure <mmoncure@gmail.com>)
List pgsql-general
Hi!
I want quick insert into db a lot of data (in form of triplets). Data is formed dynamical so "COPY" is not suitable.
I tried batch insert like this:

insert into triplets values (1,1,1);
insert into triplets values (1,1,1), (3,2,5), (4,5,5);
...
insert into triplets values (1,1,1), (3,2,5), (4,5,5) .... ;

The more triplets I use the quicker operation is.
With preparation it looks like this:

res = PQprepare(conn, "qu", "insert into triplets values ($1::bigint, $2::bigint, $3::float);",3, NULL);
...
res = PQprepare(conn, "qu", "insert into triplets values ($1::bigint, $2::bigint, $3::float), ($4::bigint, $5::bigint,
$6::float),($7::bigint, $8::bigint, $9::float), ($10::bigint, $11::bigint, $12::float);",12, NULL); 
...

The question:
Is there any way to prepare query with any number of triplets without casting such a long string?

Thank you.


pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: earthdistance
Next
From: Allan Kamau
Date:
Subject: Re: batch insertion