Re: [EXT]Re: running \copy through perl dbi ?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: "Johnson, Bruce E - (bjohnson)" <bjohnson(at)arizona(dot)edu>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: [EXT]Re: running \copy through perl dbi ?
Date: 2023-12-10 20:02:52
Message-ID: c4126f8b-2ff1-4f89-b085-dede708ac987@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 12/10/23 10:34, Johnson, Bruce E - (bjohnson) wrote:
>
>> On Dec 10, 2023, at 10:41 AM, Vincent Veyron <vv(dot)lists(at)wanadoo(dot)fr
>> <mailto:vv(dot)lists(at)wanadoo(dot)fr>> wrote:
>>
>> External Email
>>
>> On Fri, 8 Dec 2023 10:45:28 -0500

>>
>> Duh! I just realized that what I proposed with system() is a command
>> line approach.
>>
>> As David Johnston mentionned, you can use the SQL COPY command.
>
> One thing to remember with the Perl DBI is that you can use a string
> variable in the $dbh->do() command.
>
> Perl uses 2 different string variable delimiters:
>
> 1)  ‘ ‘ , which is exactly what you enter $s= ‘\copy * from foo as
> json’; will send that to the database without the need for escaping
> anything (unless you need to enter an actual ‘ in the command, in which
> case method two is better)

The issue is \copy is not a SQl statement, it is a psql(Postgres command
line client) meta-command. This means it can only be used in psql.

> --
> Bruce Johnson
> University of Arizona
> College of Pharmacy
> Information Technology Group
>
> Institutions do not have opinions, merely customs
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message veem v 2023-12-11 08:59:21 Re: Question on overall design
Previous Message Johnson, Bruce E - (bjohnson) 2023-12-10 18:34:55 Re: [EXT]Re: running \copy through perl dbi ?