pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Adrian Klaver <adrian.klaver@aklaver.com>
To: Вадим Самохин <samokhinvadim@gmail.com>
To: pgsql-general@lists.postgresql.org
Subject: Re: copy file from a client app to remote postgres isntance
Date: Mon, 7 Nov 2022 10:24:46 -0800
Message-ID: <da571604-48ea-3c3e-d1df-53b4c1b2dc76@aklaver.com> (raw)
In-Reply-To: <CAGVmuwoKkos2ssA7-MNpsQkxO=0ouOGS9PtqzFViJ2+0SDeXkQ@mail.gmail.com>
References: <CAGVmuwoKkos2ssA7-MNpsQkxO=0ouOGS9PtqzFViJ2+0SDeXkQ@mail.gmail.com>

On 11/7/22 8:57 AM, Вадим Самохин 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 
> <http://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. B|ut it's quite an unnatural way to write database 
> code. Has anything changed in the last ten years? Or, is there a better 
> wayto copy file contents in a remote database?
> 

1) Set up postgres_fdw:

https://www.postgresql.org/docs/current/postgres-fdw.html

on local machine to point at table on remote machine and then \copy or 
COPY to local machine.

2) Copy the CSV file to remote machine and then do \copy or COPY there.

-- 
Adrian Klaver
adrian.klaver@aklaver.com





view thread (11+ messages)  latest in thread

Message-ID: <da571604-48ea-3c3e-d1df-53b4c1b2dc76@aklaver.com>
Permalink:  ../da571604-48ea-3c3e-d1df-53b4c1b2dc76@aklaver.com/
Also on:    postgresql.org/message-id/da571604-48ea-3c3e-d1df-53b4c1b2dc76@aklaver.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: adrian.klaver@aklaver.com, samokhinvadim@gmail.com
  Subject: Re: copy file from a client app to remote postgres isntance
  In-Reply-To: <da571604-48ea-3c3e-d1df-53b4c1b2dc76@aklaver.com>
  References: <CAGVmuwoKkos2ssA7-MNpsQkxO=0ouOGS9PtqzFViJ2+0SDeXkQ@mail.gmail.com> <da571604-48ea-3c3e-d1df-53b4c1b2dc76@aklaver.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