pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
flat file database to postgres
3+ messages / 3 participants
[nested] [flat]

* flat file database to postgres
@ 2004-03-16 12:33  noor@cs.man.ac.uk
  0 siblings, 1 reply; 3+ messages in thread

From: noor@cs.man.ac.uk @ 2004-03-16 12:33 UTC (permalink / raw)
  To: pgsql-sql


Hi

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

Thanks




^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: flat file database to postgres
@ 2004-03-16 13:30  Frank Finner <postgresql@finner.de>
  parent: noor@cs.man.ac.uk
  0 siblings, 1 reply; 3+ messages in thread

From: Frank Finner @ 2004-03-16 13:30 UTC (permalink / raw)
  To: noor@cs.man.ac.uk; +Cc: pgsql-sql

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.


^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: flat file database to postgres
@ 2004-03-16 14:04  Tatsuo Ishii <t-ishii@sra.co.jp>
  parent: Frank Finner <postgresql@finner.de>
  0 siblings, 0 replies; 3+ messages in thread

From: Tatsuo Ishii @ 2004-03-16 14:04 UTC (permalink / raw)
  To: postgresql@finner.de; +Cc: noor@cs.man.ac.uk; pgsql-sql

> 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



^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2004-03-16 14:04 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-16 12:33 flat file database to postgres noor@cs.man.ac.uk
2004-03-16 13:30 ` Frank Finner <postgresql@finner.de>
2004-03-16 14:04   ` Tatsuo Ishii <t-ishii@sra.co.jp>

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