Re: [GENERAL] UPDATE cell from text file

From: Bob Kline <bkline(at)rksystems(dot)com>
To: "Jason C(dot) Wells" <jcwells(at)u(dot)washington(dot)edu>
Cc: pgsql-general(at)postgreSQL(dot)org
Subject: Re: [GENERAL] UPDATE cell from text file
Date: 1999-10-24 00:37:44
Message-ID: Pine.LNX.4.10.9910232028300.28391-100000@rksystems.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 24 Oct 1999, Jason C. Wells wrote:

> This has got to be easy but I am having a hard time finding the right
> docs.
>
> What I want to do is analogous to:
>
> UPDATE website SET content='contents of a big ass file that I dont want to
> type on the command line' where filename='index.html';
>
> How can I do this?
>
> Can I do this without writing a seperate shell and/or perl script?
>
> Also, is there a stdio stream that I can use to pipe data into SQL
> commands? Man, If I had this I could get a lot done in a hurry.
>
> FWIW, I am not looking for COPY-ing delimited data from a flat file into a
> table. I don't want to make new rows. I am trying to bring the contents of
> an entire file into an existing single cell (namely content) of a table.
>
> Am I going to be stuck just putting pointers to files in my database? Ugg,
> I really want ALL my data in one place.
>

Just out of curiosity, what's the drawback of a perl script here? It
would be pretty trivial.

....
open BAF, "$ARGV[0]" or die "Can't open $ARGV[0]: $!";
$contents = "";
while (read, BAF, $buf, 10240) { $contents .= $buf; }
$sth = $dbh->prepare("UPDATE website
SET content = ?
WHERE filename = ?");
$sth->execute($content, $ARGV[1]) or die $DBI::errstr;
....

--
Bob Kline
mailto:bkline(at)rksystems(dot)com
http://www.rksystems.com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 1999-10-24 01:57:33 Re: [GENERAL] select max(oid)
Previous Message Michael Plump 1999-10-24 00:01:45 Re: [GENERAL] user authentication failed (#210)