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

Поиск
Список
Период
Сортировка
От Amit Kapila
Тема Re: Add \i option to bring in the specified file as a quoted literal
Дата
Msg-id CAA4eK1JrgOjhv4PMKCDb3L9Wd1P2yjzH5OZ8D-8kK2Ah1bzmMw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Add \i option to bring in the specified file as a quoted literal  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Ответы Re: Add \i option to bring in the specified file as a quoted literal  (Alvaro Herrera <alvherre@2ndquadrant.com>)
Список 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 по дате отправления:

Предыдущее
От: Amit Kapila
Дата:
Сообщение: Server is not getting started with log level as debug5 on master after commit 3147ac
Следующее
От: Haribabu kommi
Дата:
Сообщение: Re: Heavily modified big table bloat even in auto vacuum is running