Re: Add \i option to bring in the specified file as a quoted literal

From: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>
To: Alvaro Herrera <alvherre(at)2ndquadrant(dot)com>
Cc: Piotr Marcinczyk <pmarcinc(at)gmail(dot)com>, pgsql-hackers <pgsql-hackers(at)postgresql(dot)org>, Bruce Momjian <bruce(at)momjian(dot)us>
Subject: Re: Add \i option to bring in the specified file as a quoted literal
Date: 2013-11-22 05:39:48
Message-ID: CAA4eK1JrgOjhv4PMKCDb3L9Wd1P2yjzH5OZ8D-8kK2Ah1bzmMw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Nov 22, 2013 at 1:33 AM, Alvaro Herrera
<alvherre(at)2ndquadrant(dot)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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Haribabu kommi 2013-11-22 06:42:15 Re: Heavily modified big table bloat even in auto vacuum is running
Previous Message Amit Kapila 2013-11-22 04:00:43 Server is not getting started with log level as debug5 on master after commit 3147ac