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 1gwCCZ-0007rU-Tl for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 20:41:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwCCW-0008Jl-Fh for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 20:41:12 +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 1gwCCU-0008JY-Io for pgsql-general@lists.postgresql.org; Tue, 19 Feb 2019 20:41:12 +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 1gwCCR-0000d3-D5 for pgsql-general@postgresql.org; Tue, 19 Feb 2019 20:41:09 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.west.internal (Postfix) with ESMTP id D95D9335E; Tue, 19 Feb 2019 15:41:05 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 19 Feb 2019 15:41:06 -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=w CHCvlk/6OD1/cPgdtRthA1B7zAsveegh3r2tUfLC4E=; b=knxEadzW+qysUyB/V RhkK6TON8YYzo8hc/VRwpUKi0QR/B4fEBz18ZKytjD3QYzfLShtQ+lRcEqeKt32z F5oZGFIYwjJm+o15O0hzlm3sRE19/41aCwOGlXUaQcH17IhfDJeQ03ctq90vHxTh 76YjSCzGV8g0BlLMStUpW5Wx4dv9LNM9QwQxT2Z33C6tRBMc1/8wS++woU33nvtE eqs2fZlmudH6ZzQkbtaFZR/S5Q05mtqd1V7PaObCTQkpViNH/XjYjbqAD2v3EHbW 9y58uStWQRt/nyKlJDeMPsp+Lr+wwclizURnyCSoDWpp+xayXvE7kMDrEBA51P3X 7WL8w== 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=wCHCvlk/6OD1/cPgdtRthA1B7zAsveegh3r2tUfLC 4E=; b=UvopevMp//nWyaK+0IaNSvPBcvq+EHtQfYVzkSLWR9ZoTgK0f3ut6Z4F/ 3OOegSgi1vLwuW1DwSUiDrYjPYeG4l41aPF1NrdPbEjZU2vgA+djGtr1aBRgDSF9 x4BHG/2PMZyS7aF8/XuFXCpbDBtwq4tHAcCDZXNvvAogswZgjQhQmqEiHfsGj8/5 gfDzyj7RcdM9mlcPa92jUBTk9AaS5uxWtMBYG09Swv4ow+V3xBcopkuZdBa+X4gf 6y5XSbHedRS43VIVChqQqUXI/5I2spAErMn5O9xaZfneybRTodYSAk5Pt4MT6UwX wsAoqO1ARfwyJijYFEXQT3RZ4VBYg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtdeggddufeelucdltddurdegtdelrddttd dmucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfquhht necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeejnecuhfhrohhmpeetughr ihgrnhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtg homheqnecukfhppeejuddrvdduvddrudehtddrvddtvdenucfrrghrrghmpehmrghilhhf rhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomhenucevlhhush htvghrufhiiigvpedt X-ME-Proxy: Received: from [192.168.1.4] (unknown [71.212.150.202]) by mail.messagingengine.com (Postfix) with ESMTPA id 71F47E423B; Tue, 19 Feb 2019 15:41:04 -0500 (EST) Subject: Re: procedures and transactions To: Rob Nikander , Postgres General References: From: Adrian Klaver Message-ID: Date: Tue, 19 Feb 2019 12:41:03 -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: 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 12:31 PM, Rob Nikander wrote: > Hi, > > I’m trying to understand how procedures work with transactions. I tried the code below - it’s a simple procedure to print some notices and commit a transaction. If I call it from psql after a `begin`, then it gives an error. What does that error mean? Are procedures not allowed to commit/rollback if they are called within in an outer transaction? > > 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? > > thanks, > Rob > > create or replace procedure t_test(n integer) > as $$ > begin > raise notice 'current isolation level: %', (select current_setting('transaction_isolation')); > raise notice 'current txid: %', (select txid_current()); > raise notice '---'; > commit; > raise notice 'current isolation level: %', (select current_setting('transaction_isolation')); > raise notice 'current txid: %', (select txid_current()); > end; > $$ language plpgsql; > > psql> begin; > psql> call t_test(1); Don't use the begin; call t_test(1); NOTICE: current isolation level: read committed NOTICE: current txid: 592 NOTICE: --- NOTICE: current isolation level: read committed NOTICE: current txid: 593 CALL A function already starts in a transaction. > > NOTICE: current isolation level: read committed > NOTICE: current txid: 111490 > NOTICE: --- > ERROR: invalid transaction termination > > > > > -- Adrian Klaver adrian.klaver@aklaver.com