omni_txn extension provides functionality for storing typed information in a
This is most useful to maintain information across multiple queries in the transaction, particularly with RLS (Row Level Security) policies in mind.
Setting a variable¶
Within a transaction's context, one can set a named variable with its type specified through the type of the value:
This code above sets a boolean-typed variable called
my_variable. In cases
when the type can't be figured out, type casting comes to the rescue:
The last set variable value and type are set until the end of the current transaction boundary.
Both value and the type of the variable can be changed by subsequent calls to
Getting a variable¶
In order to get a variable from the transaction's context, one needs to specify a default value with a type in order to get a value:
The above will return the value of
false if it is not found.
Will the default value be returned if variable is set to
set_variable was used to set a
If a mismatching type information is passed to
get_variable will raise an error indicating the mismatching types in details.