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 1gwDFJ-0003RI-DA for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 21:48:09 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwDFF-0007dJ-Sc for pgsql-general@arkaria.postgresql.org; Tue, 19 Feb 2019 21:48:05 +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 1gwDFF-0007dC-9d for pgsql-general@lists.postgresql.org; Tue, 19 Feb 2019 21:48:05 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwDFC-00027Q-JO for pgsql-general@postgresql.org; Tue, 19 Feb 2019 21:48:04 +0000 Received: by mail-ot1-x341.google.com with SMTP id g1so36840564otj.11 for ; Tue, 19 Feb 2019 13:48:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:mime-version:subject:date:references:to:in-reply-to:message-id; bh=KBXjH1qihgbjXD/oDseXxS+KKu8P5exkPS46hVByjOQ=; b=b3xE+WeD8k7eCtn4CuMLGTAteQC0d/PLxWMEobenHEvEbNRTpQno0kpaOWTljyOTCq llH+rLG4TLJjO5VSBW6EG+SCKX8L5gJCfxpTwWLgmEZYF8+eqQv3AXLQW1FhKVGbrtb8 FEBfxUS+y/WWtTnvIZO15jYgOJV4JUMEf5EffH/K48+yB7mmmLlhNtGBXmDB0eG6ixfy Tl48i7ShQsyadQiOGNR3P5qlXhupUB6+IiJnfZ3VI2QPCCmalhzpkqUOGtt6ofFWyQ8f KlK8BUkKJ8fdWEIFyEahfowzrTil/71rv6y9KDfpauQpQJ4UJZGjO8/8vGP1XjJHamcG y/ww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:date:references:to :in-reply-to:message-id; bh=KBXjH1qihgbjXD/oDseXxS+KKu8P5exkPS46hVByjOQ=; b=MMAc4mMQmHoqXiPqpyxhX40q0aU1s4COTe3LV1bY3FlziD5TyRoiFldoPtm6w2F2uW k6bb6sRhNKg+TAVktMUmM/FeREH0zHOFly6zuBSWSZs10hkqw3FJBKH4rJKI2Hz6MYZM f3wTxZ+CTSPDztEAROjXEx9gfm2F2Mtjh7L86la/TiCZaty28McqUvY0i9UTAdAAtoK0 j1+IrJ0QZElBF9B93MW2mmcTB2usaBb1XyvaBsS2dANMTA3+8EzodCqoPKK/cE9aJLJs Z9ib7MnCBzRzL1Wf5QeMEi58e27aif6oBIuAydkgBocUQhoMn7a5emC4ywndDxUf4OZ/ dp9A== X-Gm-Message-State: AHQUAua0mTS4PC+TbLOEM1XLZC5TfhMKcYqeQoh8Jd6+xY5OqHzki8cs x0dztEowksMNoGSJ0ye1pykbZaB1 X-Google-Smtp-Source: AHgI3IbOwdrhjOpEwKko0Sq7tfUSUpriwymY6Zp8Vg/Z0n+6eb4faAvm6i3jYUQ19feOfYCg0T/RxA== X-Received: by 2002:a9d:7651:: with SMTP id o17mr2814672otl.279.1550612881725; Tue, 19 Feb 2019 13:48:01 -0800 (PST) Received: from [192.168.0.29] ([189.216.189.67]) by smtp.gmail.com with ESMTPSA id v2sm3171013otk.60.2019.02.19.13.48.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 13:48:01 -0800 (PST) From: Rob Nikander Content-Type: multipart/alternative; boundary="Apple-Mail=_84DD2A1C-A62E-42CA-8A3F-122CA90C21BF" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Re: procedures and transactions Date: Tue, 19 Feb 2019 15:48:00 -0600 References: To: Postgres General In-Reply-To: Message-Id: <72DE4DF2-7013-4D03-AD28-426BFD1B78A0@gmail.com> X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_84DD2A1C-A62E-42CA-8A3F-122CA90C21BF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 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=E2=80=99t like the value = in `current_setting('transaction_isolation=E2=80=99)`. Rob > On Feb 19, 2019, at 2:38 PM, David G. Johnston = wrote: >=20 > On Tuesday, February 19, 2019, Rob Nikander > wrote: > Are procedures not allowed to commit/rollback if they are called = within in an outer transaction? >=20 > https://www.postgresql.org/docs/11/sql-call.html = >=20 > 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? >=20 > https://www.postgresql.org/docs/11/plpgsql-transactions.html = >=20 > David J. >=20 --Apple-Mail=_84DD2A1C-A62E-42CA-8A3F-122CA90C21BF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 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=E2=80=99t like = the value in `current_setting('transaction_isolation=E2=80=99)`.

Rob

On Feb 19, 2019, at 2:38 PM, David G. Johnston <david.g.johnston@gmail.com> wrote:

On Tuesday, February = 19, 2019, Rob Nikander <rob.nikander@gmail.com> wrote:
 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?

 https://www.postgresql.org/docs/11/plpgsql-transactions.html

David = J.


= --Apple-Mail=_84DD2A1C-A62E-42CA-8A3F-122CA90C21BF--