From: Vincent Veyron <vv.lists@wanadoo.fr>
To: pgsql-general@lists.postgresql.org
Subject: Re: running \copy through perl dbi ?
Date: Fri, 8 Dec 2023 19:12:59 +0100
Message-ID: <20231208191259.ea787e20149bf6c3817e6cd4@wanadoo.fr> (raw)
In-Reply-To: <CAEs=6DmZLwYre2AF8Li0HgL8AKFG3NwAzGEonLO0TGPk2fsZdg@mail.gmail.com>
References: <CAEs=6DmZLwYre2AF8Li0HgL8AKFG3NwAzGEonLO0TGPk2fsZdg@mail.gmail.com>
On Fri, 8 Dec 2023 10:45:28 -0500
David Gauthier <dfgpostgres@gmail.com> wrote:
>
> I'm trying to run a PG client side "\copy" command from a perl script. I
> tried using $dbh->do("\\copy ...") but it barffed when it saw the '\'...
> ERROR: syntax error at or near "\"
Hi David,
This works for me :
#create file
my $sql = qq {\\copy ( $sub_query ) to '$location' with null as '' delimiter ';' csv header } ;
my $db_name = 'xxxxxx' ;
my @args = ( 'psql', '-c', $sql, $db_name ) ;
system( @args ) == 0 or die "Bad copy: $?" ;
--
Bien à vous, Vincent Veyron
https://marica.fr
Logiciel de gestion des contentieux juridiques, des contrats et des sinistres d'assurance
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: vv.lists@wanadoo.fr
Subject: Re: running \copy through perl dbi ?
In-Reply-To: <20231208191259.ea787e20149bf6c3817e6cd4@wanadoo.fr>
References: <CAEs=6DmZLwYre2AF8Li0HgL8AKFG3NwAzGEonLO0TGPk2fsZdg@mail.gmail.com> <20231208191259.ea787e20149bf6c3817e6cd4@wanadoo.fr>
* 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