PostgreSQL - Variables on transaction-level Do PostgreSQL have variables at transaction level? If not, is it possible to implement something like that relatively easily? Unfortunately, I am still relatively inexperienced with PostgreSQL and have only found out that you can define settings at session level. 

I am currently trying to implement a historization like Hibernate has directly in PostgreSQL. A short info for which they do not know Hibernate: Hibernate has a table for revisions.  It contains an ID, the time and other information. For each table there is a "_AUD" table. Every change within the same transaction gets the same revision ID. 

To implement this directly in PostgreSQL, I would need a variable that I can use within a transaction and whose value can only be used within the same transaction. My idea is that every time a transaction is historized, a function queries if an ID exists for the transaction, if not, it creates one, otherwise it returns the already created one.

I use the latest PostgreSQL version.
From today's point of view it was rather a stupid idea or bad design and I would pass this parameter directly to the database.