Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHSF9-0004Eh-55 for pgsql-general@arkaria.postgresql.org; Tue, 30 Oct 2018 11:31:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gHSF7-00017l-7H for pgsql-general@arkaria.postgresql.org; Tue, 30 Oct 2018 11:31:29 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gHSF6-00017S-VB for pgsql-general@lists.postgresql.org; Tue, 30 Oct 2018 11:31:29 +0000 Received: from smtp.burggraben.net ([2a01:4f8:140:50a2::3:1]) by magus.postgresql.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gHSF3-0003be-Ej for pgsql-general@lists.postgresql.org; Tue, 30 Oct 2018 11:31:28 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp.burggraben.net (Postfix) with ESMTP id 2BFD56002F8 for ; Tue, 30 Oct 2018 12:31:24 +0100 (CET) X-Spam-Scanned: by amavisd-new at exwg.net Received: from smtp.burggraben.net ([127.0.0.1]) by localhost (ns.burggraben.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id C4MhBJMWpIWA for ; Tue, 30 Oct 2018 12:31:12 +0100 (CET) Received: from elch.exwg.net (elch.exwg.net [IPv6:2001:470:7120:1:127b:44ff:fe4f:148d]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "elch.exwg.net", Issuer "Christoph Moench-Tegeder" (verified OK)) by smtp.burggraben.net (Postfix) with ESMTPS for ; Tue, 30 Oct 2018 12:31:12 +0100 (CET) Received: by elch.exwg.net (Postfix, from userid 1000) id 2F15427334; Tue, 30 Oct 2018 12:31:12 +0100 (CET) Date: Tue, 30 Oct 2018 12:31:12 +0100 From: Christoph Moench-Tegeder To: pgsql-general@lists.postgresql.org Subject: Re: Problem with commit in function Message-ID: <20181030113111.GA63213@elch.exwg.net> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ## Mike Martin (redtux1@gmail.com): > Subject: Problem with commit in function You can't commit inside a FUNCTION - and there's an obvious ERROR if you try to do that: "invalid transaction termination". Only since version 11 you can use a PROCEDURE and COMMIT/ROLLBACK inside that - and the procedure must be written in PL/pgSQL (you don't get transaction control in SQL procedures - but beside the LANGUAGE marker, your code would be the same). See https://www.postgresql.org/docs/current/static/sql-createprocedure.html https://www.postgresql.org/docs/current/static/plpgsql-transactions.html > truncate table postgres_log_tmp ; You might want to look into temporary tables (perhaps even unlogged ones) - that will save you the hassle of truncating (temporary tables are even automatically removed), and with an unlogged temp table it will save you some WAL I/O. > --COMMIT; So, is this on or not? Oh, and please pay attention to the errors PostgreSQL throws at you - they're significant. Regards, Christoph -- Spare Space