Re: Problem with commit in function - Mailing list pgsql-general

From Christoph Moench-Tegeder
Subject Re: Problem with commit in function
Date
Msg-id 20181030113111.GA63213@elch.exwg.net
Whole thread Raw
In response to Problem with commit in function  (Mike Martin <redtux1@gmail.com>)
List pgsql-general
## 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


pgsql-general by date:

Previous
From: Madan Kumar
Date:
Subject: How to change standby node to sync from the new master withoutrebooting the PostgreSQL service?
Next
From: Marian Forums
Date:
Subject: Question about servicescript for stopping and starting postgresql instance