Re: Import File

From: Brent Wood <b(dot)wood(at)niwa(dot)co(dot)nz>
To: Rodrigo Africani <rafricani(at)fotinisystems(dot)com(dot)br>
Cc: Postgresql <pgsql-general(at)postgresql(dot)org>
Subject: Re: Import File
Date: 2005-08-23 21:26:57
Message-ID: 20050824091309.W77518@storm-user.niwa.co.nz
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, 23 Aug 2005, Rodrigo Africani wrote:

> Hi,
>
> I'm trying to import a sequence txt file.
> The file has fix columns ... i.e the first 10 positions is the primary key ...
> The comand copy need a delimitier but the file is seq without a delimitier.
> I look in the manual but i don't won't if it is possible.
> My problem is the file is very large ...
> 1G and I don't have a lot of memory to change the file and put delimitiers.
>

I'm not sure if you mean your input file is fixed field (eg, col1 = chars
1-10, col2=chars 11-15, etc) instead of having a specified character (eg,
"," or space or tab) between the columns.

With a delimiter, you can (very roughly):

cat <file> | psql <db> -c "copy from stdin;"

with fixed columns you can use awk:

cat <file> | awk '{print "substr(1,10), ..." }' | psql <db> -c "copy from
stdin;"

The only other inerpretation I can see from your description is that the
data is one column pet line, rather than one record per line.

In this case a simple script or program to assemble the lines into the
appropriate number of columns might be necessary, but it should be able to
read stdin and write to stdout so that you can still pipe (|) your file tp
psql.

Hope this helps,

Brent

In response to

  • Import File at 2005-08-23 14:47:57 from Rodrigo Africani

Browse pgsql-general by date

  From Date Subject
Next Message Bill Moseley 2005-08-23 21:45:24 Optimize a VIEW question
Previous Message Mark Probert 2005-08-23 20:54:14 drop table before create