pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Chris Mair <chris@1006.org>
To: Laurenz Albe <laurenz.albe@cybertec.at>
To: a <372660931@qq.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: How to insert bulk data with libpq in C?
Date: Tue, 18 Dec 2018 11:57:09 +0100
Message-ID: <59eda4cff9a454701320e2a69569c156@smtp.hushmail.com> (raw)
In-Reply-To: <51c2cd6edffd7308e317635d022690c23096eeae.camel@cybertec.at>
References: <tencent_CE6C7379E293054D70DED60603941818B408@qq.com>
	<80ed60d54a29cb8bf3058dc0b9f5d44cf244378c.camel@cybertec.at>
	<a147f147f02ace8c2268d39a5933093f@smtp.hushmail.com>
	<51c2cd6edffd7308e317635d022690c23096eeae.camel@cybertec.at>


>>>> May I ask the proper (fast) way of inserting bulk data and if possible, an example would be very appreciated.
>>>>
>>>> Please note that the data I would like to insert contains arrays (float8[]).
>>>>
>>>> By the way, my environment is Windows 10, PostgreSQL 11 and compiling with Visual Studio 2017.
>>>
>>> That would be COPY:
>>> https://www.postgresql.org/docs/current/sql-copy.html
>>
>> In particular,
>>
>> copy table (col1, col2, ...) from stdin with binary
> 
> Hmm, binary requires that you know the binary PostgreSQL representation.
> PostgreSQL might be faster converting text to its internal representation
> than your application program...
> 
> The big exception here is of course bytea, where the binary representation
> is definitely smaller and easy to create.

Hi,

yes.
I understood the data is already binary and OP wants to store it binary, but
of course this might not be the case.

>> Also, I suggest transaction bundling (one commit every 1000 records or so),
>> depending on context.
> 
> Why that?
> It might be useful if you expect the load to fail in the middle and want
> to be able to restart from there.  But normally, doing it all in one
> transaction is simpler.

Yes. That would be the special case with one commit every N records, where
N is the total count :)

I just wanted to make shure OP will not commit after each COPY.

Bye.
Chris.







view thread (5+ messages)

Message-ID: <59eda4cff9a454701320e2a69569c156@smtp.hushmail.com>
Permalink:  ../59eda4cff9a454701320e2a69569c156@smtp.hushmail.com/
Also on:    postgresql.org/message-id/59eda4cff9a454701320e2a69569c156@smtp.hushmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: chris@1006.org, laurenz.albe@cybertec.at, 372660931@qq.com
  Subject: Re: How to insert bulk data with libpq in C?
  In-Reply-To: <59eda4cff9a454701320e2a69569c156@smtp.hushmail.com>
  References: <tencent_CE6C7379E293054D70DED60603941818B408@qq.com> <80ed60d54a29cb8bf3058dc0b9f5d44cf244378c.camel@cybertec.at> <a147f147f02ace8c2268d39a5933093f@smtp.hushmail.com> <51c2cd6edffd7308e317635d022690c23096eeae.camel@cybertec.at> <59eda4cff9a454701320e2a69569c156@smtp.hushmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox