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

Re: Copy entire file as one field

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Warren Massengill <warrenmassengill(at)hotmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Copy entire file as one field
Date: 2002-11-28 07:43:12
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
On Thu, 2002-11-28 at 00:40, Warren Massengill wrote:
> How can I copy several hundred small text files into a database, each file 
> going into a field called 'message' and becomming one record (with or 
> without other fields) using psql?

A bit of shell scripting:

for f in `ls small_file*`
	psql -d mydatabase -c "INSERT INTO mytable (message)
				 VALUES ('`cat $f`')"

Oliver Elphick                                Oliver(dot)Elphick(at)lfix(dot)co(dot)uk
Isle of Wight, UK                   
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
     "The earth is the LORD'S, and the fullness thereof; the
      world, and they that dwell therein."       Psalms 24:1

In response to

pgsql-novice by date

Next:From: HKDate: 2002-11-28 11:36:43
Subject: 'now' doesnt seem to work in stored procedure
Previous:From: etsuko shimabukuroDate: 2002-11-28 04:50:47
Subject: user defined function

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