Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZBT6-0001U7-5P for pgsql-general@arkaria.postgresql.org; Tue, 18 Dec 2018 09:15:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gZBT2-0007zZ-KX for pgsql-general@arkaria.postgresql.org; Tue, 18 Dec 2018 09:15:08 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZBT2-0007yA-94 for pgsql-general@lists.postgresql.org; Tue, 18 Dec 2018 09:15:08 +0000 Received: from smtp2.hushmail.com ([65.39.178.134]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gZBSu-0007aM-9u for pgsql-general@postgresql.org; Tue, 18 Dec 2018 09:15:05 +0000 Received: from smtp2.hushmail.com (localhost [127.0.0.1]) by smtp2.hushmail.com (Postfix) with SMTP id 081A0A0A65 for ; Tue, 18 Dec 2018 09:14:58 +0000 (UTC) Received: from smtp.hushmail.com (w9.hushmail.com [65.39.178.29]) by smtp2.hushmail.com (Postfix) with ESMTP; Tue, 18 Dec 2018 09:14:56 +0000 (UTC) Subject: Re: How to insert bulk data with libpq in C? To: a <372660931@qq.com> References: <80ed60d54a29cb8bf3058dc0b9f5d44cf244378c.camel@cybertec.at> Cc: pgsql-general From: Chris Mair Message-ID: Date: Tue, 18 Dec 2018 10:14:51 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:60.0) Gecko/20100101 Thunderbird/60.3.3 MIME-Version: 1.0 In-Reply-To: <80ed60d54a29cb8bf3058dc0b9f5d44cf244378c.camel@cybertec.at> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk >> 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 see also https://www.postgresql.org/docs/10/static/protocol-flow.html#PROTOCOL-COPY https://www.postgresql.org/docs/10/static/sql-copy.html#id-1.9.3.52.9.4 Also, I suggesttransaction bundling (one commit every 1000 records or so), depending on context. Bye, Chris.