Skip site navigation (1) Skip section navigation (2)

Re: inserting/updating a field with the contents of a text file

From: "Lonni J Friedman" <netllama(at)gmail(dot)com>
To: "George Pavlov" <gpavlov(at)mynewplace(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: inserting/updating a field with the contents of a text file
Date: 2007-09-25 01:14:18
Message-ID: 7c1574a90709241814k5538df41g24618b129b23ac8b@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
On 9/24/07, George Pavlov <gpavlov(at)mynewplace(dot)com> wrote:
> > psql -q -d database0 -h server -c "UPDATE table set info='`cat
> > /tmp/file.txt`' where id=3;"
> >
> > and this almost works.  The problem is that whenever there are
> > carriage returns in file.txt, the rest of the file contents never get
> > inserted (i only get the first line).
>
> Not sure what's inside your file, but the CRs are not your problem. What
> you do have to be concerned about escaping are any single quotes. You
> can do that with whatever your favorite search and replace utility is
> (e.g. ...-c"insert into table (info) values('`sed "s/'/''/g"
> file.txt`')" )
>
> Just so you know I am not making it up on the CRs here's an example:

Thanks, that appears to have been the issue.


-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
L. Friedman                                    netllama(at)gmail(dot)com
LlamaLand                       https://netllama.linux-sxs.org

In response to

Responses

pgsql-novice by date

Next:From: Richard Broersma JrDate: 2007-09-25 01:50:39
Subject: Re: inserting/updating a field with the contents of a text file
Previous:From: George PavlovDate: 2007-09-25 00:27:32
Subject: Re: inserting/updating a field with the contents of a text file

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group