Re: PERL DBD::pg question

From: Robert Grabowski <grabba(at)7bulls(dot)com>
To: Peter V Trofimov <peter_troff(at)mail(dot)ru>
Subject: Re: PERL DBD::pg question
Date: 2001-09-14 19:19:14
Message-ID: 3BA25831.38FFFD87@7bulls.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Peter V Trofimov wrote:

> Strange thing:
>
> I can execute this query in psql without any errors:
>
> delete from news_pending where news_id in (37,15,38,41,43,0);
>
> but in PERL this script:
> _____________________________________________________________
> my $ids = join(',', @news_id);
> $sth = $dbh->prepare_cached("delete from news_pending where news_id in
> (?)");
> $sth->execute($ids);
> $err_str=$DBI::errstr;
> while (defined($err_str)) {
> $dbh->rollback();
> $dbh->disconnect();
> exit;
> }
> $dbh->commit();
> _______________________________________________________________
>
> executs with error:
> ERROR: pg_atoi: error in "37,15,38,41,43,0": can't parse ",15,38,41,43,0"
>
> How I can fix it?
>

If you put variables by execute method then all vars will be quoted ...
PostgreSQL try to execute this query:
delete from news_pending where news_id in ('12,13,14') not
delete from news_pending where news_id in (12,13,14)

Try to make this query like this...

my $dbh;
eval {
$dbh = DBI->connect('dbi:Pg:____', {RaiseError => 1, PrintError => 0,
AutoCommit => 0});
my $sth = $dbh->prepare('delete from news_pending where news_id = ?');
foreach my $id (@news_id) {
$sth->execute($id);
}
$sth->commit();
};
if ($@) {
$dbh->rollback();
}
$dbh->disconnect();

regards...

--
Robert Grabowski 7bulls.com S.A.

email: Robert(dot)Grabowski(at)7bulls(dot)com
office: +48 56 655 79 65
mobile: +48 604 181 907

Browse pgsql-general by date

  From Date Subject
Next Message David. E. Goble 2001-09-14 19:36:36 I could do with some guidance
Previous Message Jeff Eckermann 2001-09-14 18:56:59 Re: Can I insert two different variables from form into different tables using one SQL query ?