Thread: Fwd: [GENERAL] statement id
No response on general to my sort of esoteric question... Any info here on hackers? --elein ---------- Forwarded Message ---------- Subject: [GENERAL] statement id Date: Tue, 18 Mar 2003 19:03:35 -0800 From: elein <elein@sbcglobal.net> To: pgsql-general@postgresql.org Cc: elein@varlena.com Is there any way to find out the statement context in a server function? Is there anyway to find out the transaction context in a server function? I have a plpython function I want to run and it can store data for the context of a session. But I only want the memory to last the duration of a statement or a transaction. It is not a trigger function which has a transaction dictionary. If I knew the statement or transaction id I could initialize the memory for multiple calls within the session. Statement (subselect) level would be best as it would enable managing data from several calls to the same function. Sort of. If this were a C function, would it be easier to have this information? thanks, elein -- ----------------------------------------------------------------------------- ----------- elein@varlena.com Database Consulting www.varlena.com I have always depended on the [QA]of strangers. ---------------------------(end of broadcast)--------------------------- TIP 2: you can get off all lists at once with the unregister command (send "unregister YourEmailAddressHere" to majordomo@postgresql.org) ------------------------------------------------------- -- ---------------------------------------------------------------------------------------- elein@varlena.com Database Consulting www.varlena.com I have always depended on the [QA] of strangers.
elein wrote: > Is there any way to find out the statement context in a server function? > Is there anyway to find out the transaction context in a server function? > [...snip...] > > If this were a C function, would it be easier to have this information? > I don't know anything about plpython, but I'd guess the info you're looking for is not available to it. In C, I think (but have not tried) you could use GetCurrentTransactionId() to put the current transaction id into a global variable, and allocate memory for other globals in TopTransactionContext. Then use a change in transaction id to signal a need to reallocate/reinitialize your globals. Not sure if this is what you were looking for, but HTH. Joe
Yes, this is exactly what I'm looking for. I was hoping the connection context information might be available in one of the stat tables, some SQL variable or function call. The ability to have data persist across function calls without having to resort to C is really very useful, but having some context information is crucial. elein On Saturday 22 March 2003 15:48, Joe Conway wrote: > elein wrote: > > Is there any way to find out the statement context in a server function? > > Is there anyway to find out the transaction context in a server function? > > [...snip...] > > > If this were a C function, would it be easier to have this information? > > I don't know anything about plpython, but I'd guess the info you're > looking for is not available to it. > > In C, I think (but have not tried) you could use > GetCurrentTransactionId() to put the current transaction id into a > global variable, and allocate memory for other globals in > TopTransactionContext. Then use a change in transaction id to signal a > need to reallocate/reinitialize your globals. > > Not sure if this is what you were looking for, but HTH. > > Joe -- ---------------------------------------------------------------------------------------- elein@varlena.com Database Consulting www.varlena.com I have always depended on the [QA] of strangers.