From: Tatsuo Ishii <t-ishii@sra.co.jp>
To: postgresql@finner.de
Cc: noor@cs.man.ac.uk
Cc: pgsql-sql@postgresql.org
Subject: Re: flat file database to postgres
Date: Tue, 16 Mar 2004 23:04:00 +0900 (JST)
Message-ID: <20040316.230400.39151407.t-ishii@sra.co.jp> (raw)
In-Reply-To: <20040316143023.29ad9dbd.postgresql@finner.de>
References: <4133.80.46.172.2.1079440437.squirrel@popeye.cs.man.ac.uk>
<20040316143023.29ad9dbd.postgresql@finner.de>
> On Tue, 16 Mar 2004 12:33:57 -0000 (GMT) noor@cs.man.ac.uk sat down, thought long and then wrote:
>
> >
> > Hi
> >
> > Does anybody know how to export data from a flatfile (using perl) database
> > to postgres?
> >
> > Thanks
>
> If it is some kind of CSV (text with separators) you could use DBD::CSV for reading and DBD::Pg for
> writing. Or you read the file with Perl´s standard functions, treat the data to be
> PostgreSQL-insert-query-compatible (regarding apostrophes for example) and then use DBD::Pg (that´s
> what I usually do). If you have some kind of DBase files, you can use DBD::XBase.
I wrote a user defined C function which read a file and returns it.
test=# SELECT * FROM exttable('/etc/group', ':') AS g(gname TEXT, dummy TEXT, gid INTEGER, gmembers TEXT) LIMIT 10;
gname | dummy | gid | gmembers
--------+-------+-----+-----------------
root | x | 0 | root
bin | x | 1 | root,bin,daemon
daemon | x | 2 | root,bin,daemon
sys | x | 3 | root,bin,adm
adm | x | 4 | root,adm,daemon
tty | x | 5 |
disk | x | 6 | root
lp | x | 7 | daemon,lp
mem | x | 8 |
kmem | x | 9 |
(10 rows)
Of course this kind of function could be dangerous if you
thoughtlessly use it. Anyway I could post it if there's enough
interest.
--
Tatsuo Ishii
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: t-ishii@sra.co.jp, postgresql@finner.de, noor@cs.man.ac.uk
Subject: Re: flat file database to postgres
In-Reply-To: <20040316.230400.39151407.t-ishii@sra.co.jp>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox