From: | Christoph Moench-Tegeder <cmt(at)burggraben(dot)net> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Problem with commit in function |
Date: | 2018-10-30 11:31:12 |
Message-ID: | 20181030113111.GA63213@elch.exwg.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
## Mike Martin (redtux1(at)gmail(dot)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
From | Date | Subject | |
---|---|---|---|
Next Message | Marian Forums | 2018-10-30 12:09:39 | Question about servicescript for stopping and starting postgresql instance |
Previous Message | Madan Kumar | 2018-10-30 11:19:39 | How to change standby node to sync from the new master without rebooting the PostgreSQL service? |