Обсуждение: flat file database to postgres

Поиск
Список
Период
Сортировка

flat file database to postgres

От
noor@cs.man.ac.uk
Дата:
Hi

Does anybody know how to export data from a flatfile (using perl) database
to postgres?

Thanks



Re: flat file database to postgres

От
Frank Finner
Дата:
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.

Regards, Frank.

Re: flat file database to postgres

От
Tatsuo Ishii
Дата:
> 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 | rootbin    | x     |   1 | root,bin,daemondaemon | x
|  2 | root,bin,daemonsys    | x     |   3 | root,bin,admadm    | x     |   4 | root,adm,daemontty    | x     |   5 |
disk  | x     |   6 | rootlp     | x     |   7 | daemon,lpmem    | 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