Re: Add \i option to bring in the specified file as a quoted literal - Mailing list pgsql-hackers

From Amit Kapila
Subject Re: Add \i option to bring in the specified file as a quoted literal
Date
Msg-id CAA4eK1JrgOjhv4PMKCDb3L9Wd1P2yjzH5OZ8D-8kK2Ah1bzmMw@mail.gmail.com
Whole thread Raw
In response to Re: Add \i option to bring in the specified file as a quoted literal  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Responses Re: Add \i option to bring in the specified file as a quoted literal
List pgsql-hackers
On Fri, Nov 22, 2013 at 1:33 AM, Alvaro Herrera
<alvherre@2ndquadrant.com> wrote:
> Piotr Marcinczyk escribió:
>
>>         <varlistentry>
>> +         <term><literal>\ib <replaceable class="parameter">filename</replaceable> [ <replaceable
class="parameter">quote_string</replaceable>] </literal></term> 
>> +         <listitem>
>> +         <para>
>> +         The <literal>\ib</> command appends content of file <literal>filename</literal>
>> +         to current query buffer. If parameter <literal>quote_string</literal>
>> +         is not set, no quotation is used. If it is set, content of file will be
>> +         quoted by <literal>quote_string</literal> enclosed in <literal>$</literal>.
>> +         </para>
>> +         </listitem>
>> +       </varlistentry>
>
> Doesn't this quoting thing seem like a usability problem?  I mean,
> there's no way you can possibly know what string to use unless you first
> verify the contents of the file yourself.  I think this is something
> that should be done automatically by psql.
>
> But, really, having to read stuff and transform into a quoted literal
> seems wrong to me.  I would like something that would read into a client
> variable that can later be used as a positional parameter to a
> parametrized query, so
>
> \ib homer ~/photos/homer.jpg
> insert into people (name, photo) values ('Homer', :homer);
Isn't something similar already supported as mentioned in docs:

One example use of this mechanism is to copy the contents of a file
into a table column. First load the file into a variable and then
interpolate the variable's value as a quoted string:

testdb=> \set content `cat my_file.txt`
testdb=> INSERT INTO my_table VALUES (:'content');

or do you prefer an alternative without any kind of quote using \ib?

With Regards,
Amit Kapila.
EnterpriseDB: http://www.enterprisedb.com



pgsql-hackers by date:

Previous
From: Amit Kapila
Date:
Subject: Server is not getting started with log level as debug5 on master after commit 3147ac
Next
From: Haribabu kommi
Date:
Subject: Re: Heavily modified big table bloat even in auto vacuum is running