Обсуждение: BUG #13897: backquotes and inserting files into columns.

Поиск
Список
Период
Сортировка

BUG #13897: backquotes and inserting files into columns.

От
arthur.lewis@hypermediasystems.com
Дата:
The following bug has been logged on the website:

Bug reference:      13897
Logged by:          Arthur Lewis
Email address:      arthur.lewis@hypermediasystems.com
PostgreSQL version: 9.3.10
Operating system:   Ubuntu Linux 14 (32 bit)
Description:

In the manual (http://www.postgresql.org/docs/9.3/static/app-psql.html) it
says in order to insert a file into the database all you do is the
following:

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

The manual also says:

Within an argument, text that is enclosed in backquotes (`) is taken as a
command line that is passed to the shell. The output of the command (with
any trailing newline removed) replaces the backquoted text.

I have a file called my_file.txt and it has 53604 bytes.  When I do this

testdb=> \set content `cat my_file.txt`
testdb=> select length(:'content');
 length
--------------
        53603

Because of back-quotes I've just lost a byte (a trailing newline) and the
original file has been changed.

If there is a better way than using back-quotes please let me know.