Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y5Okm-0007gY-Qe for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2014 01:04:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Y5Okl-0007rH-Rd for pgsql-general@arkaria.postgresql.org; Mon, 29 Dec 2014 01:04:11 +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 1Y5Okk-0007rB-Qu for pgsql-general@postgresql.org; Mon, 29 Dec 2014 01:04:10 +0000 Received: from mwork.nabble.com ([162.253.133.43]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Y5Okg-0005ri-PT for pgsql-general@postgresql.org; Mon, 29 Dec 2014 01:04:09 +0000 Received: from msam.nabble.com (unknown [162.253.133.85]) by mwork.nabble.com (Postfix) with ESMTP id 5009BEEF9B1 for ; Sun, 28 Dec 2014 17:04:05 -0800 (PST) Date: Sun, 28 Dec 2014 18:04:04 -0700 (MST) From: David G Johnston To: pgsql-general@postgresql.org Message-ID: <1419815044308-5832233.post@n5.nabble.com> In-Reply-To: <54A06C58.2020009@aklaver.com> References: <54A01E44.9050105@aklaver.com> <54A06C58.2020009@aklaver.com> Subject: Re: Rollback on include error in psql MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.3 (/) 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 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? 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). 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