Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwDy3-00073o-6Q for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 22:34:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwDy1-0006b3-Eg for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 22:34:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwDy0-0006aR-E6 for pgsql-general@lists.postgresql.org; Tue, 19 Feb 2019 22:34:21 +0000 Received: from wout2-smtp.messagingengine.com ([64.147.123.25]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwDxw-0003Ba-Rv for pgsql-general@postgresql.org; Tue, 19 Feb 2019 22:34:19 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id 2444F353C; Tue, 19 Feb 2019 17:34:15 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 19 Feb 2019 17:34:15 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=V QlV4VNh5qHodpcEf703EaA+7P7p9zI+S+ipFAc1toY=; b=A4FnUMYEOoON2LUB3 cg/OBvnTZinuYtnoAfgFckUw9m0sWybT5uiQdppW4pIggZ7PqTYllIcfi1L1FKNj 4RKQiY3laXOceoSXkdFBuuBTuoc52D6sV1kITZJCO/bDzKngSIU4G6VbQn2z+azr lPaI+jPH2CmftFR3kWAxhqpvFAZ3XN4aYiiMeQBXKEHUz3PgwRgS5BgD7F5ekT0X lAyS6f6YtLAT8g5uwb1iWFS3zs2pETS8PkjYFDXHzxTALMxfXvUqtkE30JWDjxoW e62s/qJ93qGZSMyGE9sN10mO1/QU0803MDuHTHXinPAfByko3JsVbW7zc67Nfq5S 7RlAQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=VQlV4VNh5qHodpcEf703EaA+7P7p9zI+S+ipFAc1t oY=; b=QOIDPkgUWhWJcsYtITEzRKyQ6gGz1McG7JOBRfvOTCanQdL994EPDJovH HqKMoADXs0lQtjI75Sz4rp0qYXgYxqJ96mfS/MUmVJTQqPVkLdPEzUfM2gYf5FBU eED1jkB6y4BzeS1eGluAZKF7CKInGBqiqM9lZkI0G/7tvM2E8RqJ0jad85YGIk4A 8HvH0taMWdqhKDzXv+9hSjFlsTQjyvaN4HQJ7zY9Yi6wICKU5an3qI+OuBlsXRMr H6K1d+/PzyqgWr0zRbh+Sbzq3vnTuNlL4h0Fy3xU729dFLagVKLGsfBFKOnZJO3X fIQB2oZbYcPvOjMhW+RxfXVFxdEQg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtdeggdduiedtucdltddurdegtdelrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucfkphepjedurddv uddvrdduhedtrddvtddvnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkh hlrghvvghrsegrkhhlrghvvghrrdgtohhmnecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id E3137E409D; Tue, 19 Feb 2019 17:34:13 -0500 (EST) Subject: Re: procedures and transactions To: Rob Nikander , Postgres General References: <72DE4DF2-7013-4D03-AD28-426BFD1B78A0@gmail.com> From: Adrian Klaver Message-ID: <2f23e41c-aeb5-b430-b8a3-48373b6db6d1@aklaver.com> Date: Tue, 19 Feb 2019 14:34:09 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.0 MIME-Version: 1.0 In-Reply-To: <72DE4DF2-7013-4D03-AD28-426BFD1B78A0@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2/19/19 1:48 PM, Rob Nikander wrote: > I thought if I had some application logic that needed a certain kind of > transaction (maybe a non-default isolation level), I could hide that > fact in a procedure. App code (Java/Python/whatever) could remain > unaware of transactions (except maybe needing to retry after a failure) > and simply send `call foo(?, ?)` to the DB. But maybe that kind of > design is not supported, and application code needs to start > transactions and set isolation levels. Is that accurate?  I supposed a > procedure could throw an exception if it doesn’t like the value in > `current_setting('transaction_isolation’)`. Per the docs in the link David posted: https://www.postgresql.org/docs/11/sql-call.html "If CALL is executed in a transaction block, then the called procedure cannot execute transaction control statements. Transaction control statements are only allowed if CALL is executed in its own transaction." So: psql> begin; psql> call t_test(1); will not work. > > Rob > >> On Feb 19, 2019, at 2:38 PM, David G. Johnston >> > wrote: >> >> On Tuesday, February 19, 2019, Rob Nikander > > wrote: >> >>  Are procedures not allowed to commit/rollback if they are called >> within in an outer transaction? >> >> >> https://www.postgresql.org/docs/11/sql-call.html >> >> Also, I tried putting a `start transaction` command in the >> procedure. I got another error: `unsupported transaction command >> in PL/pgSQL`. Are procedures not allowed to start transactions? Or >> is there another command? >> >> >> https://www.postgresql.org/docs/11/plpgsql-transactions.html >> >> David J. >> > -- Adrian Klaver adrian.klaver@aklaver.com