Unix Technical Forum

perl DBI and SQL COPY

This is a discussion on perl DBI and SQL COPY within the pgsql Novice forums, part of the PostgreSQL category; --> What is the accepted way (if there is one) of using the PostgreSQL COPY command in the setting of ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 08:18 PM
Sean Davis
 
Posts: n/a
Default perl DBI and SQL COPY

What is the accepted way (if there is one) of using the PostgreSQL COPY
command in the setting of perl DBI. I realize this is slightly
off-topic, so feel free to send me elsewhere.

Thanks,
Sean


---------------------------(end of broadcast)---------------------------
TIP 7: don't forget to increase your free space map settings

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 08:18 PM
Sean Davis
 
Posts: n/a
Default Re: perl DBI and SQL COPY

I answered my own question (actually, the DBD::Pg email list did).
Something like this works:

SQL:
create table test1 (
id serial primary key,
testdat varchar,
testdat2 varchar);

perl:
#!/usr/bin/perl
use strict;
use warnings;
use DBI;

my $dbh = DBI->connect('dbi:Pg:dbname=test;host=sherlock',
'',
'',
{AutoCommit => 1},
);

my $sql = qq{COPY test1 (testdat, testdat2) from STDIN};
my $sth = $dbh->prepare($sql);
$sth->execute() || die $sth->errstr;
foreach my $i (101..200) {
my $line = "abc$i\tdef$i\n";
my $ret = $dbh->func($line, 'putline');
print $ret . "\n";
}
$dbh->func('endcopy');
$dbh->disconnect;


Sean


On Jan 4, 2005, at 5:52 AM, Sean Davis wrote:

> What is the accepted way (if there is one) of using the PostgreSQL
> COPY command in the setting of perl DBI. I realize this is slightly
> off-topic, so feel free to send me elsewhere.
>
> Thanks,
> Sean
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 7: don't forget to increase your free space map settings



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:38 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com