Skip site navigation (1) Skip section navigation (2)

COPY and turning off autocommit

From: Maciek Sakrejda <msakrejda(at)truviso(dot)com>
To: pgsql-jdbc(at)postgresql(dot)org
Subject: COPY and turning off autocommit
Date: 2009-11-17 17:40:34
Message-ID: 895e58dd0911170940p4fefb12fi1fe0c5a8240ccb5@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-jdbc
I've found that since COPY does not use the sendQueryPreamble method
in QueryExecutorImpl, it fails to issue the necessary BEGIN if it's
the first statement after autocommit is set to off.

A workaround is to just issue a "SELECT 1" before the COPY, but this
is pretty ugly.

I'm not quite sure what the proper fix is: does COPY need to go
through the full sendQueryPreamble code path (specifically,
processDeadParsedQueries() and processDeadPortals())? Also, that code
is tied into the ResultHandler interface, and COPY does not really fit
well into that paradigm. I don't think we can we just call
sendQueryPreamble(), sendSync(), processResults(), and *then* move to
COPY code, since sendQueryPreamble() might do nothing if we're already
in a transaction. I suppose we could pass in a null ResultHandler and
see if the handler returned is null (in which case there is no BEGIN
to process), but that seems egregiously ugly.

Any thoughts?

-- 
Maciek Sakrejda | Software Engineer | Truviso

1065 E. Hillsdale Blvd., Suite 230
Foster City, CA 94404
(650) 242-3500 Main
(650) 242-3501 F
www.truviso.com

Responses

pgsql-jdbc by date

Next:From: Kris JurkaDate: 2009-11-18 11:21:38
Subject: Re: commit and rollback don't throw exceptions when they should
Previous:From: Radosław SmoguraDate: 2009-11-12 21:21:11
Subject: Re: Implementation of query timeout

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group