Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1osnm8-0008Vc-Rg for pgsql-general@arkaria.postgresql.org; Wed, 09 Nov 2022 16:18:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1osnm7-0001hu-P4 for pgsql-general@arkaria.postgresql.org; Wed, 09 Nov 2022 16:18:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1osnm7-0001hk-Fe for pgsql-general@lists.postgresql.org; Wed, 09 Nov 2022 16:18:03 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1osnm5-0000c5-Bf for pgsql-general@lists.postgresql.org; Wed, 09 Nov 2022 16:18:02 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id E1F05806A; Wed, 9 Nov 2022 17:17:59 +0100 (CET) Date: Wed, 9 Nov 2022 17:17:59 +0100 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: copy file from a client app to remote postgres isntance Message-ID: <20221109161759.6bnobepy6cfpl5ig@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: <34c71bc8-e4cc-05f8-c0e5-211754c55940@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="tk6uq5ua6fqlfz5j" Content-Disposition: inline In-Reply-To: <34c71bc8-e4cc-05f8-c0e5-211754c55940@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --tk6uq5ua6fqlfz5j Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2022-11-07 14:40:40 -0600, Ron wrote: > On 11/7/22 10:57, =D0=92=D0=B0=D0=B4=D0=B8=D0=BC =D0=A1=D0=B0=D0=BC=D0=BE= =D1=85=D0=B8=D0=BD wrote: > I have an application that must copy a local file in csv format to a > postgres table on a remote host. The closest solution is this one (ht= tps:// > stackoverflow.com/a/9327519/618020). It boils down to specifying a \c= opy > meta-command in a psql command: >=20 > psql -U %s -p %s -d %s -f - < =20 >=20 > and executing it. But it's quite an unnatural way to write database c= ode. Has anything changed in the last ten years? Or, is there a better way = to copy file contents in a remote database? >=20 >=20 > I'd write a small Python script, using the csv module to read the data and > psycopg2 to load it. If you use insert statements it will be significantly slower (which may not matter for small files or one-off actions). If you use copy_from() you don't have to parse it (but then why use Python at all?) hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --tk6uq5ua6fqlfz5j Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmNr0rcACgkQ8g5IURL+ KF0bFg/9ELmiIUZ21DSuXTdiWI/pf6Apolwb1WYBClz6fsPNnAH7rQYU7Wadpr9V 9ySNHwct7lrFxWa4GR2SxhLfDHOhIZWQrXczEzY2hjfKX/bfTUgdg4P4VnZZB1/k z4Svn18XoEzieE2c/XXdbf7M7PONfQ44sjr3ZVYK3q+Rn460xhvRxrMVWV5SqJ4s T+DcdxBLXqqgxtCT1fqhdtv6GtLBde76OefoMWYr9x6UxK/nu1tTQHQo3oYqqjNH S+3D7REbopAHmIAIpAz8Zh32x89P1vvPTX2I34QIPipOinnfVBeUbq88GNaqy8yN hL4DwXpCx6qXsqjRrcIx6iGmgfyMFxa+UgHSW/zpi7t85CB6VaXE5yy5ZpjO4GQ2 EkELX8uMTf5gBnlu9t1itLswnneC6KotryXOCw4jsbxkCaA4RMu0Sz9wUgUmVlca 7Mlm4lHou2pHaSlFKWUl1CT0cetLsCdYwk/wOH6qfw0FAxhUjsVEHDfR9YczmNc8 TdVMzGpA8QK0l9WPpAVRp0jfnYEu1ZZDUEa+0KIQie9E0Gknl6oi4Dn9ULDJdlF+ Fsmpgl5xssdwa7he5mHh8gpGzXP7KdHzuL4BpeLcWhYcjbn/d6/UpsgJiAaVK+2m kbRcU4ZbKfD5g3fDI7nVtdhzCfstQJpEQKCFDgn4dbT3ioLp1f8= =5cMh -----END PGP SIGNATURE----- --tk6uq5ua6fqlfz5j--