How to mimic Perl's DBD::Pg's do('COPY...')/pg_putline/pg_endcopy ?
Kynn Jones <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi. With Perl's counterpart of psycopg2, namely the DBD::Pg module, one can
use PostgreSQL's COPY facility to write data directly to a database without
the need to create an intermediate file.
For example, the following selectively copies some records from a file into
the table given by $table_name:
open my $in, '<', 'GI-NORMOUS.TXT' or die $!;
$dbh->do(qq(COPY "$table_name" $specs FROM stdin));
while (<$in>) {
next unless check($_);
$dbh->pg_putline(make_record($_));
}
$dbh->pg_endcopy;
How can this functionality be achieved from psycopg2? Can it be done
without having to create an intermediate file?
TIA!
kynn
_______________________________________________
Psycopg mailing list
Psycopg-IAPFreCvJWPBWskQ1e/[email protected]
http://lists.initd.org/mailman/listinfo/psycopg