473,321 Members | 1,877 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,321 software developers and data experts.

Nested SPI_exec's

Hi All,

I'm in the process of moving a rather complicated plpgsql stored procedure to
a C module and I'm curious about how to implement the for each row syntax in
C. My understanding is that if you perform an SPI_exec whilst looping
through the results of another exec the allocated SPITupleTable will be
automatically unallocated. Is this correct or am I way off here and it's
actually safe to iterate through the tuples in an SPITupleTable and perform
additional SPI_exec's? Thinking about this now it probably is but I thought
it better to ask.

The other query I have relates to the transaction 'safe-ness' of a C module.
If I initiate all of this within a transaction (from outside the C module),
is everything within the SPI module automagically encapsulated with the
transaction or do I have to manage the transaction from within the SPI
module?

Rgds,

Jason

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 12 '05 #1
2 1705
Jason Godden <ja*********@optushome.com.au> writes:
I'm in the process of moving a rather complicated plpgsql stored procedure to
a C module and I'm curious about how to implement the for each row syntax in
C. My understanding is that if you perform an SPI_exec whilst looping
through the results of another exec the allocated SPITupleTable will be
automatically unallocated. Is this correct or am I way off here and it's
actually safe to iterate through the tuples in an SPITupleTable and perform
additional SPI_exec's?
SPI won't auto-deallocate tuple tables unless you leave the procedure
(ie call SPI_finish). It's true that the static variable SPI_tuptable
will be overwritten by each exec, but you can just copy that into a
local variable and continue to operate on the tuple table till you
are done with it. It'd probably be wise to explicitly do
SPI_freetuptable when you are done with a result, if you're making
more of them inside a loop...
The other query I have relates to the transaction 'safe-ness' of a C module.
If I initiate all of this within a transaction (from outside the C module),
is everything within the SPI module automagically encapsulated with the
transaction or do I have to manage the transaction from within the SPI
module?


You don't and in fact can't manage transactions in a callable procedure.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

Nov 12 '05 #2
Hi Tom,

Thanks for the fast response. One learns something new everyday!

Cheers,

Jason

On Tue, 7 Oct 2003 12:14 am, Tom Lane wrote:
Jason Godden <ja*********@optushome.com.au> writes:
I'm in the process of moving a rather complicated plpgsql stored
procedure to a C module and I'm curious about how to implement the for
each row syntax in C. My understanding is that if you perform an
SPI_exec whilst looping through the results of another exec the allocated
SPITupleTable will be automatically unallocated. Is this correct or am I
way off here and it's actually safe to iterate through the tuples in an
SPITupleTable and perform additional SPI_exec's?


SPI won't auto-deallocate tuple tables unless you leave the procedure
(ie call SPI_finish). It's true that the static variable SPI_tuptable
will be overwritten by each exec, but you can just copy that into a
local variable and continue to operate on the tuple table till you
are done with it. It'd probably be wise to explicitly do
SPI_freetuptable when you are done with a result, if you're making
more of them inside a loop...
The other query I have relates to the transaction 'safe-ness' of a C
module. If I initiate all of this within a transaction (from outside the
C module), is everything within the SPI module automagically encapsulated
with the transaction or do I have to manage the transaction from within
the SPI module?


You don't and in fact can't manage transactions in a callable procedure.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to ma*******@postgresql.org so that your
message can get through to the mailing list cleanly

---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faqs/FAQ.html

Nov 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Glen | last post by:
I have a Struts action form which contains a bean. I am trying to display a bean retrieved from the database in this form using the nested tag. Can anyone help me? I continue to get an error...
6
by: Andy Baker | last post by:
Hi there, I'm learning Python at the moment and trying to grok the thinking behind it's scoping and nesting rules. I was googling for nested functions and found this Guido quote:...
3
by: Erik Bongers | last post by:
Hi, Nested classes only seem to be able to access static members of the surrounding class : class SurroundingClass { public: class InnerClass { public:
10
by: nimmi_srivastav | last post by:
Below you will see an example of a nested conditional expression that this colleague of mine loves. He claims that it is more efficient that a multi-level if-else-if structure. Moreover, our...
6
by: B0nj | last post by:
I've got a class in which I want to implement a property that operates like an indexer, for the various colors associated with the class. For instance, I want to be able to do 'set' operations...
8
by: Robert W. | last post by:
I've almost completed building a Model-View-Controller but have run into a snag. When an event is fired on a form control I want to automatically updated the "connnected" property in the Model. ...
1
by: Tomas Sieger | last post by:
Hi all, I'm in doubt with the following code: class Base { public: class Nested {}; }; class Derived:public Base { public: class Nested {
77
by: Peter Olcott | last post by:
http://www.tommti-systems.de/go.html?http://www.tommti-systems.de/main-Dateien/reviews/languages/benchmarks.html The above link shows that C# is 450% slower on something as simple as a nested loop....
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.