jcpa...@uw.edu ("John Payne") writes:
> I'm using DBD::Pg to access a PostgreSQL database with a Perl script, and
> having trouble with AutoCommit: the standard syntax fails to set it.  I have
> tried both setting it during the connection: 
>
>  
>
>        my $dbh = DBI->connect ( 'DBI:Pg:dbname=' . $dbname, $dbuser,
> $passwd,{AutoCommit => 0, RaiseError => 1});
>
>  
>
> .and setting it after the connection is made:
>
>  
>
>         $dbh->{Autocommit} = 0;
>
>  
>
> Neither seems to work, because I get an error message when I try the
> $dbh->begin_work() command,

Have you considered looking at the fine manual?

,----
|  begin_work
| 
|        This method turns on transactions until the next call to
|        "commit" or "rollback", if "AutoCommit" is currently
|        enabled. If it is not enabled, calling begin_work will issue an
|        error.
`----

The reason for this is that PostgreSQL doesn't support 'no
autocommit'. Because of this, the driver emulates this by
transparently starting a transaction as soon as some statement is
supposed to be executed. Since each session can only have one open
transaction at any given time, trying to start a transaction explicitly
while transactions are being started automatically is an error. It
also doesn't make much sense to try :-).

Reply via email to