Take the 2-minute tour ×

I am trying to do the following:

UPDATE bodycontent set body=CONTENT_FROM_FILE where contentid=12943363;

I tried the following based on the highest voted answer to this question.

\set contentfill `cat Foo.txt`
UPDATE bodycontent set body=:'contentfill' where contentid=12943363;

This results in the following error.

ERROR:  syntax error at or near ":"                                                  
LINE 1: UPDATE bodycontent set body=:'contentfill' where contentid=1...              

Is there a clean, simple and effective way to achieve this on the psql command line?

Here is the output of psql --version:

psql (PostgreSQL) 8.4.17 
share|improve this question
Postgres' version? –  Milen A. Radev Apr 24 at 3:57
@MilenA.Radev, Updated with version. –  merlin2011 Apr 24 at 3:59

1 Answer 1

After much searching, I discovered this answer, which does not directly discuss the problem of reading files, but gave me the necessary ingredient to make this work for my ancient Postgres.

\set contentFill `cat Foo.txt`
\set quoted_contentFill '\'' :contentFill '\''
UPDATE bodycontent SET body=:quoted_contentFill WHERE contentid=12943363; 

Naturally, this will fail if there are un-escaped quotes inside Foo.txt, but I can easily preprocess to ensure there are none.

share|improve this answer

Your Answer


