Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBfLc-00BpXu-2p for pgsql-general@arkaria.postgresql.org; Fri, 08 Dec 2023 18:13:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rBfLY-00AIub-Jh for pgsql-general@arkaria.postgresql.org; Fri, 08 Dec 2023 18:13:08 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rBfLY-00AIuS-4Z for pgsql-general@lists.postgresql.org; Fri, 08 Dec 2023 18:13:08 +0000 Received: from smtp-21.smtpout.orange.fr ([80.12.242.21] helo=smtp.smtpout.orange.fr) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rBfLQ-00ArJQ-VD for pgsql-general@lists.postgresql.org; Fri, 08 Dec 2023 18:13:07 +0000 Received: from X250.home ([90.65.235.18]) by smtp.orange.fr with SMTP id BfLPrUofdW9bDBfLPrFB3L; Fri, 08 Dec 2023 19:12:59 +0100 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1702059179; bh=hQn4OB5cHUXYy0Y8QC+uzOTc1KX/mLoJAmiTaUA3YTk=; h=Date:From:To:Subject:In-Reply-To:References; b=PbS1NXOpReO5MVZBNlQ4N/6NtR9BQ7bFRghL5Gauca7aWu4V97WdWZevlY+2fyy06 sns1wTgzeH5XW4DCawGe9m/Uacztn6dxvdRGpXgOXdGkTIt3UEtjY0rC1fh+jjH/ix YC7lsyyKgCN+LMaMCecFDdfk5IUQjuhAU5ptv/yMxL3tdNN9cpGr0SZbpgR6WM72ll tr+B1R+1CLc5a3BrfW7EVSnlI4cGQADlVbdbJiU3aFLSXwymOtxGtIlW8TROKHbTMe 8OTE6ln4ZqaMoNhzHqml9mQiHoR6+4T7BP+mGkU+LpbL9lHHB4ZgB6fAIjY37gDXBQ 7g6VFfjfU+g9A== X-ME-Helo: X250.home X-ME-Date: Fri, 08 Dec 2023 19:12:59 +0100 X-ME-IP: 90.65.235.18 Date: Fri, 8 Dec 2023 19:12:59 +0100 From: Vincent Veyron To: pgsql-general@lists.postgresql.org Subject: Re: running \copy through perl dbi ? Message-Id: <20231208191259.ea787e20149bf6c3817e6cd4@wanadoo.fr> In-Reply-To: References: X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 8 Dec 2023 10:45:28 -0500 David Gauthier wrote: >=20 > 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 =3D qq {\\copy ( $sub_query ) to '$location' with null as '' d= elimiter ';' csv header } ; my $db_name =3D 'xxxxxx' ; my @args =3D ( 'psql', '-c', $sql, $db_name ) ; =20 system( @args ) =3D=3D 0 or die "Bad copy: $?" ; --=20 Bien =E0 vous, Vincent Veyron https://marica.fr Logiciel de gestion des contentieux juridiques, des contrats et des sinistr= es d'assurance