pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Ron <ronljohnsonjr@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: copy file from a client app to remote postgres isntance
Date: Wed, 9 Nov 2022 12:57:23 -0600
Message-ID: <f1881d8f-6bab-5366-be42-13e86bb8efcb@gmail.com> (raw)
In-Reply-To: <20221109161759.6bnobepy6cfpl5ig@hjp.at>
References: <CAGVmuwoKkos2ssA7-MNpsQkxO=0ouOGS9PtqzFViJ2+0SDeXkQ@mail.gmail.com>
	<34c71bc8-e4cc-05f8-c0e5-211754c55940@gmail.com>
	<20221109161759.6bnobepy6cfpl5ig@hjp.at>

On 11/9/22 10:17, Peter J. Holzer wrote:
> On 2022-11-07 14:40:40 -0600, Ron wrote:
>> On 11/7/22 10:57, Вадим Самохин 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 (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.
> 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?)

If OP does not want to embed psql in his app, then he must find a different 
solution.  Python is such an option.


-- 
Angular momentum makes the world go 'round.





view thread (11+ messages)  latest in thread

Message-ID: <f1881d8f-6bab-5366-be42-13e86bb8efcb@gmail.com>
Permalink:  ../f1881d8f-6bab-5366-be42-13e86bb8efcb@gmail.com/
Also on:    postgresql.org/message-id/f1881d8f-6bab-5366-be42-13e86bb8efcb@gmail.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: ronljohnsonjr@gmail.com
  Subject: Re: copy file from a client app to remote postgres isntance
  In-Reply-To: <f1881d8f-6bab-5366-be42-13e86bb8efcb@gmail.com>
  References: <CAGVmuwoKkos2ssA7-MNpsQkxO=0ouOGS9PtqzFViJ2+0SDeXkQ@mail.gmail.com> <34c71bc8-e4cc-05f8-c0e5-211754c55940@gmail.com> <20221109161759.6bnobepy6cfpl5ig@hjp.at> <f1881d8f-6bab-5366-be42-13e86bb8efcb@gmail.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