Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y5cZX-0003BT-Do for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2014 15:49:31 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y5cZW-0006wC-Ui for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2014 15:49:30 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y5cZV-0006vq-MH for pgsql-general@postgresql.org; Mon, 29 Dec 2014 15:49:29 +0000 Received: from out1-smtp.messagingengine.com ([66.111.4.25]) by magus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Y5cZR-0005Dt-4E for pgsql-general@postgresql.org; Mon, 29 Dec 2014 15:49:28 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 1E62F209C8 for ; Mon, 29 Dec 2014 10:49:22 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute6.internal (MEProxy); Mon, 29 Dec 2014 10:49:22 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=aklaver.com; h= x-sasl-enc:message-id:date:from:mime-version:to:subject :references:in-reply-to:content-type:content-transfer-encoding; s=mesmtp; bh=2KrrwAXIDdqi70hTLiEZPsU2A8A=; b=cFIqhWdXQJeEu1Ag5s aCY7XYzLvFMlWcwYIqha+l+t/2EMgaMsOHCgQs0VehWM2AGXXIllf9QMcU2tXk6V 0cIt+F/QSWhdJ6sS4Znp3CFBhrsZY3p9jsCkdZPSQR7z2JqfDOoGLzgMcQBYU4Dr tOXjwxBB9n3NQW4RZBSUw+xSA= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=x-sasl-enc:message-id:date:from :mime-version:to:subject:references:in-reply-to:content-type :content-transfer-encoding; s=smtpout; bh=2KrrwAXIDdqi70hTLiEZPs U2A8A=; b=LrpU4aJDkJa6HnGe1Lza8DWKzwfDZ+3qjxK876M7eZ7nbr+WzlmJqG ALX5ItB+5MlSP+kFM5QR+E6C4zX419GD/nF7d+vq6MjYi2Xs6BftgiO43CFxY3AQ nKOPX7FNsF9lz/SENy0FCBPvTfjXw33sj6YJfNljaGHCb1Dqtk8PY= X-Sasl-enc: WvKv+LBNAi0y1dRniVLMyerx2o6DtrmiQJnRw3mvntPc 1419868161 Received: from [192.168.1.2] (unknown [174.21.251.95]) by mail.messagingengine.com (Postfix) with ESMTPA id 84BA5680097; Mon, 29 Dec 2014 10:49:21 -0500 (EST) Message-ID: <54A17800.1010700@aklaver.com> Date: Mon, 29 Dec 2014 07:49:20 -0800 From: Adrian Klaver User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: David G Johnston , pgsql-general@postgresql.org Subject: Re: Rollback on include error in psql References: <54A01E44.9050105@aklaver.com> <54A06C58.2020009@aklaver.com> <1419815044308-5832233.post@n5.nabble.com> In-Reply-To: <1419815044308-5832233.post@n5.nabble.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org On 12/28/2014 05:04 PM, David G Johnston wrote: > Adrian Klaver-4 wrote >> On 12/28/2014 10:06 AM, Viktor Shitkovskiy wrote: >>> I include my own scripts. Each of them creates some table or makes some >>> changes to existing tables. >> >> It is hard to say where to go from here without more information. > > really? Yes. The if, ands and buts for each of the options by themselves much less in combination would indicate that an answer is dependent on what is actually happening in the scripts. We have a fragment of the main script and not much information as to what is actually happening in the called scripts. See below why this is important. > > This seems like a documentation bug (or, at the least worth more > documentation explanation) at minimum; two of them probably: > > 1) it is not documented that "\include" is a valid alias for "\i" > 2) the implications of \include being a client-side mechanic and thus, > invisible to the server, is not well explained. Specifically that a failure > to include is the equivalent of simply omitting the statement altogether > (aside from the psql warning). Agreed. > > I would suggest an enhancement whereby psql will send a guaranteed-to-fail > command to the server upon failing to find an included file - at least in > non-interactive mode; in interactive mode the warning is likely sufficient > though the interplay with auto-commit would be concerning. > > >> The options you are passing to psql all have caveats: > > I'm not seeing how any of those caveats are coming into play here. > > The ON_ERROR_STOP behavior is actually surprising since psql does indeed > return 3 but even with single transaction and auto-commit=off any updates > prior to the include are committed. > > This isn't that difficult to test... > [db] > CREATE TABLE testtbl (col text PRIMARY KEY); > INSERT INTO testtbl VALUES ( 'value' ); > > [script] > UPDATE testtbl SET col = 'some other value'; > \i some_missing_file.sql > UPDATE testtbl SET col = 'yet another value'; > [/script] > > execute using: > > psql --single-transaction --set ON_ERROR_STOP=1 --set AUTOCOMMIT=off -f >