Re: [GENERAL] Unstable C Function

2016-09-22 Thread Tom Lane
Ian Campbell writes: > OK, so SPI is only suitable for single-call functions, right? It's usable by strictly nested functions, but a multi-call SRF is more like a coroutine. > If another > function in the query attempted to use SPI, I assume there would be a > deadlock? No, the second arrival w

Re: [GENERAL] Unstable C Function

2016-09-22 Thread Ian Campbell
I'm going to rewrite it to use your tuplestore suggestion. OK, so SPI is only suitable for single-call functions, right? If another function in the query attempted to use SPI, I assume there would be a deadlock? Regards, Ian On Thu, Sep 22, 2016 at 7:25 PM Tom Lane wrote: > Ian Campbell write

Re: [GENERAL] Unstable C Function

2016-09-22 Thread Tom Lane
Ian Campbell writes: > Thanks for personally replying, Tom. I appreciate it. > You are correct. In the interim, I found the following change solved the > issue: > SPI_finish(); // move to here > SRF_RETURN_DONE(funcctx); That might work under light usage, but the problem with it is you're blocki

Re: [GENERAL] Unstable C Function

2016-09-21 Thread Ian Campbell
Thanks for personally replying, Tom. I appreciate it. You are correct. In the interim, I found the following change solved the issue: SPI_finish(); // move to here SRF_RETURN_DONE(funcctx); I'll look into tuplestore. Thanks for the hint. Fixed IMMUTABLE. Regards Ian Campbell On Thu, Sep 22, 20

Re: [GENERAL] Unstable C Function

2016-09-21 Thread Tom Lane
Ian Campbell writes: > The function works fine on first call, sometimes more, then either resets > the connection or throws this on any further calls: > ERROR: cache lookup failed for type 0 SQL state: XX000 I think the core problem here is that you're dealing with pass-by-reference results from

[GENERAL] Unstable C Function

2016-09-21 Thread Ian Campbell
I'm running PG 9.5 on Win 10 64-bit. I'm compiling C under VS 2016. I am forming a function that will evolve into a somewhat complex beast. To test out my initial efforts, the function accepts an array of int4 (this works fine and the code for processing it is not shown here). The function then gr