Hi!
I posted the following message to the general list but no answer.Could
you please help?

I have some problems with the SPI memory management (at least I think
this is the problem).

What I'm trying to do is to get the Query related to a select statement,
alter it and produce a new SPI_plan that will execute. To do so, I
retrieve the query from the _SPI_plan->qtlist, alter it (seems OK in
nodeToString) and then use some SPI functions copied in my code to
produce the new _SPI_plan. In more details, I begin a new my_SPI
session, call my_SPI_prepare and pass the query. The code is almost the
same with that in spi.c apart from that I do not call pg_parse and
pg_analyze_and_rewrite.Then I begin a new SPI session and pass the new
plan.

Now, the problem:

Everything works fine only when I execute my function just after I have
initiated a new psql session. When I try to call it again, the Query
structure inside the new plan seems empty (all fields shown by
nodeToString seem to have no values). Even if I reload my shared library
(load command),the same problem appears. I allocate memory for the Query
object with palloc() outside a SPI or my_SPI session.

Any hints?

Thanks in advance!
Ntinos Katsaros

PS: I'm not very good at C!


---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

               http://archives.postgresql.org

Reply via email to