Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UB8c1-000769-Jh for pgsql-jdbc@arkaria.postgresql.org; Thu, 28 Feb 2013 18:53:49 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UB8c0-0005jn-QG for pgsql-jdbc@arkaria.postgresql.org; Thu, 28 Feb 2013 18:53:48 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UB8bz-0005it-8l for pgsql-jdbc@postgresql.org; Thu, 28 Feb 2013 18:53:47 +0000 Received: from nm4-vm0.bullet.mail.bf1.yahoo.com ([98.139.213.129]) by makus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UB8bx-0005P2-Du for pgsql-jdbc@postgresql.org; Thu, 28 Feb 2013 18:53:46 +0000 Received: from [98.139.212.148] by nm4.bullet.mail.bf1.yahoo.com with NNFMP; 28 Feb 2013 18:53:44 -0000 Received: from [98.139.212.193] by tm5.bullet.mail.bf1.yahoo.com with NNFMP; 28 Feb 2013 18:53:44 -0000 Received: from [127.0.0.1] by omp1002.mail.bf1.yahoo.com with NNFMP; 28 Feb 2013 18:53:44 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 27945.90352.bm@omp1002.mail.bf1.yahoo.com Received: (qmail 4036 invoked by uid 60001); 28 Feb 2013 18:53:43 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ymail.com; s=s1024; t=1362077623; bh=AgE8F6KkHTMa8xtbYtWZN7XAGudoihN4t8inBTa5qVU=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=gp6sUot9xMwn7l2Bo9wOlgxFgHwtJUBHhhxzIz/6ENTq2nMWUTWv/eUvKPm0ASVgiKryXTUDChJAxeqUNf+52wcJUI+1Tn7qvJ3/epdBFkCAgJxiGJzabeSovt+wYgXGhh6ec1sWF8MWVLayuc5t3bB2uwcCYsoJasAf3NsA+nE= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=ymail.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding; b=ZADa6oVR0oKAdrDmXk/uJbAh+UgBUp6r0foPDfgRkQVrLLv0oAbTq1GaVKAh995RH21RtvIeU97aXFyFBof2YR+ynfar9ye3KQIjNjNS8K+Y/ICyXMOMtWFzaN2O/fcQlell/HBtPpUbACq79MHBiSntQ0xtCcBwysDk8o+A5sQ=; X-YMail-OSG: jyH9JqAVM1mjExaQ872fUQcrE82Te9wmOCzgj4e0G0GcSoe cHERzMBcGad3XKG62iqn.Z07dO__lrp7YUfy5mfi1jsGP2FldlaAASw8bIMf 02t421GKZqX3L9pSAFJFh6itcR7ZZjd8ANJNxX1l07r4cdUJIA4YC5JRKBoT WWgajkYy5UbKZbH9WbWO9YucoCrPJ5jOqfxpRmbVpzo0ZKbYxiOmlHyfUzYe VK0FZovvioDPqEtcZclka2zjYVvkZccklBdS.l4Khqm.V4tvJ1eOqpjQMJsF 1rnAiSPJVyh5rbE_XSI4qjpx82uDTOXQIIXyUVlm7dFZmswifdgBINZR2hRL 7wpmVGj9b2MNKu6_jp8esXN0zP7fFr.H4W3hPKJ0ZwIufFxQAu19JNWK9HHE u82O8CgJfDFygZAo1zQiwmJuGc2F4DUcAPsKEmG2RY7nzn5wyEGNzx5mY1Qg 3TMkxG4KHP7wKnYsk2Tt0B8_xRV0EzPUw2Nifr4P2ePX7yuCiT0HWIMfYavH 3J2FCqq7zC3TtvlXVMdqqdr4JJ.uxGeSOJoi8ageWswKFg61x8gAZvsNA3bt tiYWETA6qqae48YM2pWgVBBhznf5dZJ0Y6rxZ2QMyV1dl_jqeYlzgzNCfKOM 7VdLh61t7jdzBjz4jh6Xh2dN4.KvOLZSWFw-- Received: from [76.255.18.237] by web162902.mail.bf1.yahoo.com via HTTP; Thu, 28 Feb 2013 10:53:43 PST X-Rocket-MIMEInfo: 001.001, Sm9zZXBoIFByYXZhdG8gPGpvc2VwaC5wcmF2YXRvQG5vbWFnaWMuY29tPiB3cm90ZToKCj4gV2UgdXNlIFNxdWlycmVsU1FMIHRvIHRhbGsgdG8gb3VyIGRhdGFiYXNlcyB3aXRoIHRoZSBQb3N0Z3Jlcwo.IDkuMi0xMDAyIEpEQkMgZHJpdmVyLgoKSW4gbXkgcHJldmlvdXMgam9iIHRoZSBEQkFzIGhhZCBhbiBvdXRyaWdodCBiYW4gb24gdXNpbmcKU3F1aXJyZWxTUUwgYWdhaW5zdCBwcm9kdWN0aW9uIG9yIHNoYXJlZCBkZXZlbG9wbWVudCBvciB0ZXN0CmRhdGFiYXNlcyBiZWNhdXNlIG9mIGl0cyBiYWQgdHIBMAEBAQE- X-Mailer: YahooMailWebService/0.8.135.514 References: <512F84ED.3050002@nomagic.com> Message-ID: <1362077623.96612.YahooMailNeo@web162902.mail.bf1.yahoo.com> Date: Thu, 28 Feb 2013 10:53:43 -0800 (PST) From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: Automatic transactions in SELECT To: Joseph Pravato , "pgsql-jdbc@postgresql.org" In-Reply-To: <512F84ED.3050002@nomagic.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-jdbc Precedence: bulk Sender: pgsql-jdbc-owner@postgresql.org Joseph Pravato wrote: > We use SquirrelSQL to talk to our databases with the Postgres > 9.2-1002 JDBC driver. In my previous job the DBAs had an outright ban on using SquirrelSQL against production or shared development or test databases because of its bad transactional behavior.=A0 We used several other tools, none of which caused the same problems. > What gets particularly confusing with this issue is when your > query is wrong in any way, you are required to rollback the > transaction. This is viewed as a feature since otherwise, in the absence of careful exception handling, you might commit a transaction after an important step failed, possibly resulting in data loss. > Worse yet, you have to re-run any prior statements in the > transaction if you have any errors. The easiest solution is to > turn auto-commit on and hope that you never seriously screw up > data. But, we are not going to, nor allowed to do that. Did I > miss anything, maybe a setting somewhere in the JDBC driver that > can fix this issue? I recommend using savepoints, or a tool which can automatically use them: http://www.postgresql.org/docs/9.2/interactive/sql-savepoint.html FWIW, psql has an option to turn on automatic savepoint usage via the ON_ERROR_ROLLBACK option.=A0 Use that with care, though, because if you use it with a script like this, you can regret it: BEGIN; CREATE TABLE new_copy [...] ; INSERT INTO new_copy SELECT * FROM prod_dat; DROP TABLE prod_data; ALTER TABLE new_copy RENAME TO prod_data; COMMIT; Note the typo in INSERT/SELECT.=A0 With the default behavior, the script leaves you in the same state you started.=A0 Ignoring errors, you lose the contents of that table.=A0 That tends not be a problem with interactive commands, as long as copy/paste of multiple commands is not used, but it can be a problem with scripts or copy/paste. > Please note, one of the recommendations was to switch sql query > tools, turn on auto-commit, or to use save points. When I had to do ad hoc data fix queries, I always used transactions.=A0 If I wasn't sure of my syntax, I tried it on a small test database first, tried an EXPLAIN of the statement on a different connection to validate syntax, or used a savepoint. > We would rather find a solution with the JDBC driver instead of > switching tools as we have been using SquirrelSQL for over a year > with various databases. We are currently looking into the use of > save points, but as of now, any assistance is appreciated. Due to the desire of members of the community not to lose data due to a script file typo, any suggestion that a transaction continue to process subsequent statements after an error without a subtransaction is a non-starter.=A0 Maybe you can change the SquirrelSQL source code to have a feature for this, like psql does? --=20 Kevin Grittner EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company --=20 Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-jdbc