From: Christoph Moench-Tegeder <cmt@burggraben.net>
To: pgsql-general@lists.postgresql.org
Subject: Re: Problem with commit in function
Date: Tue, 30 Oct 2018 12:31:12 +0100
Message-ID: <20181030113111.GA63213@elch.exwg.net> (raw)
In-Reply-To: <CAOwYNKZBLP2WZdgqXMD421_hqfVt=KNj7OXk3an7Z89v2ybLmw@mail.gmail.com>
References: <CAOwYNKZBLP2WZdgqXMD421_hqfVt=KNj7OXk3an7Z89v2ybLmw@mail.gmail.com>
## 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.htmlhttps://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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: cmt@burggraben.net
Subject: Re: Problem with commit in function
In-Reply-To: <20181030113111.GA63213@elch.exwg.net>
References: <CAOwYNKZBLP2WZdgqXMD421_hqfVt=KNj7OXk3an7Z89v2ybLmw@mail.gmail.com> <20181030113111.GA63213@elch.exwg.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox