BUG #13897: backquotes and inserting files into columns. - Mailing list pgsql-bugs

From arthur.lewis@hypermediasystems.com
Subject BUG #13897: backquotes and inserting files into columns.
Date
Msg-id 20160128234356.2555.15307@wrigleys.postgresql.org
Whole thread Raw
List pgsql-bugs
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.

pgsql-bugs by date:

Previous
From: "Sinha, Amitava"
Date:
Subject: Re: Is Windows Posready 2009 XP operating system supported?
Next
From: reece@harts.net
Date:
Subject: BUG #13899: \det ignores visibility; patch attached