Re: How to mimic Perl's DBD::Pg's do('COPY...')/pg_putline/pg_endcopy ?
Adrian Klaver <[email protected]>
| Newsgroups | gmane.comp.python.db.psycopg.devel |
|---|---|
| Message-ID | <[email protected]> |
On Wednesday 14 October 2009 6:34:28 am Kynn Jones wrote:
> 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
In the examples section of the unpacked tarball there are two examples,
copy_to.py and copy_from.py.
--
Adrian Klaver
[email protected]