Re: copy file from a client app to remote postgres isntance - Mailing list pgsql-general

From Ron
Subject Re: copy file from a client app to remote postgres isntance
Date
Msg-id 34c71bc8-e4cc-05f8-c0e5-211754c55940@gmail.com
Whole thread Raw
In response to copy file from a client app to remote postgres isntance  (Вадим Самохин <samokhinvadim@gmail.com>)
Responses Re: copy file from a client app to remote postgres isntance  ("Peter J. Holzer" <hjp-pgsql@hjp.at>)
List pgsql-general
On 11/7/22 10:57, Вадим Самохин wrote:
Hi all,
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 (https://stackoverflow.com/a/9327519/618020). It boils down to specifying a \copy meta-command in a psql command:
psql -U %s -p %s -d %s -f - <<EOT\n here hoes a \copy meta-command \nEOT\n

and executing it. But it's quite an unnatural way to write database code. Has anything changed in the last ten years? Or, is there a better way to copy file contents in a remote database?

I'd write a small Python script, using the csv module to read the data and psycopg2 to load it.

--
Angular momentum makes the world go 'round.

pgsql-general by date:

Previous
From: Willian Colognesi
Date:
Subject: Re: Segmentation Fault PG 14
Next
From: Brad White
Date:
Subject: Re: Setting up replication on Windows, v9.4