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 1osnk0-0008MX-Hg for pgsql-general@arkaria.postgresql.org; Wed, 09 Nov 2022 16:15:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1osnjz-0002kx-Cz for pgsql-general@arkaria.postgresql.org; Wed, 09 Nov 2022 16:15:51 +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 1osnjz-0002kn-21 for pgsql-general@lists.postgresql.org; Wed, 09 Nov 2022 16:15:51 +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 1osnjt-0000aN-8R for pgsql-general@lists.postgresql.org; Wed, 09 Nov 2022 16:15:49 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 0C514806A; Wed, 9 Nov 2022 17:15:42 +0100 (CET) Date: Wed, 9 Nov 2022 17:15:42 +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: <20221109161542.63f3b2q5is5ghass@hjp.at> Mail-Followup-To: pgsql-general@lists.postgresql.org References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="jzylopev7p6rrtlf" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --jzylopev7p6rrtlf Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2022-11-07 19:57:04 +0300, =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 post= gres > table on a remote host. The closest solution is this one (https:// > stackoverflow.com/a/9327519/618020). It boils down to specifying a \copy > meta-command in a psql command: >=20 > psql -U %s -p %s -d %s -f - <=20 > and executing it. But it's quite an unnatural way to write database > code. This looks like something you would use in another programming language (maybe C or Python?) to construct a shell command. Do you want do this once (from the shell) or from code? If the former, starting psql and typing \copy table_name from 'filename.csv' ... Doesn't seem that unnatural to me. (That just invokes COPY ... FROM STDIN on the server and feeds data to it over the existing SQL connection.) If it's the latter, your programming language's postgresql library probably has a method for invoking copy. > Has anything changed in the last ten years? Or, is there a > better way to copy file contents in a remote database? COPY is the fastest way to load data. hp --=20 _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | hjp@hjp.at | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!" --jzylopev7p6rrtlf Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmNr0icACgkQ8g5IURL+ KF1jjw/+JsehGqS6tHdqXgjJTqRByKnEbNvEHiRwDlwTsVqcsvhe4ZvgNlMn9SoE I1dB3azL8fYGvi7Qc6w8oIO8OPK0Vqo9eHW3cCUj5gDDze0veoUDTSsm629985J2 dXvS6J24tFJRfdDrOato+IzdESA1yktH56eRJ+jgmli/t7TxQxoZPXIF1cWfvk7c D8jvNfI0k0+mCCPyZrt8q8WqbaiWzuRzkf7wxUTvv/tJLUpoSJick8rxOtaxQQ9F 5N5ahOKwsxzQmF8Q3JbBOLMj4dabOXtcWDpikO+JVcNRSzDkzcStpNnYejWRNyYG J68OuvHzC7umYg4P57xTEBdipUc+Ziwu6HUhUsmKoXrh31UyNhxzx9Nl9ChilT65 xP2zLCyo48ix98jzTh4S97cRoPlg6c4occz7QVXQW1ny4cpvuutq14Cga+fs2Q+S FUd0+KBc6N/9t/g68GyXpxrda/kEehvUzaoD66ib6tKhiWV8wG7CQZL35Kirz7lX gBJi2n0mpBtSsfCcwymIgueELXfOy8UoM1pNl0Gl923jF4MIyZTA9aBv7BO3FUkN ffy5aJkPd/8wutz4NmIwsaRHxvuyL1uixXvw7c1wXiMVKFdbmDnHP9l1zSOfHHvK 3be8jeIZE5dHnXrEz8XFSplVu/5qEz41hvyYVN7mFpbyy6fGXP4= =PANC -----END PGP SIGNATURE----- --jzylopev7p6rrtlf--