SPI error with non-volatile functions - Mailing list pgsql-hackers

From Tom Mercha
Subject SPI error with non-volatile functions
Date
Msg-id VI1PR02MB37123D4AF993B4288A395652F4760@VI1PR02MB3712.eurprd02.prod.outlook.com
Whole thread Raw
Responses Re: SPI error with non-volatile functions  (Andres Freund <andres@anarazel.de>)
List pgsql-hackers
Dear Hackers

I've been using SPI to execute some queries and this time I've tried to 
issue CREATE TABLE commands through SPI. I've been getting the message 
"ERROR: CREATE TABLE AS is not allowed in a non-volatile function".

I'm a bit confused because my functions are set as volatile when I got 
that result. I was sure I'd be able to issue CREATE TABLE through SPI 
because a possible return value of SPI_execute is SPI_OK_UTILITY if a 
utility command such as CREATE TABLE was executed.

Maybe the caveat is the following. I am actually invoking my function 
through CREATE LANGUAGE's inline handler using an anonymous do block. So 
maybe I need to take some additional considerations for this reason?

The following is what my functions look like:

CREATE FUNCTION myLanguage.myLanguage_function_call_handler()
RETURNS language_handler
AS 'MODULE_PATHNAME','myLanguage_function_call_handler'
LANGUAGE C VOLATILE;

CREATE FUNCTION myLanguage.myLanguage_inline_function_handler(internal)
RETURNS void
AS 'MODULE_PATHNAME','myLanguage_inline_function_handler'
LANGUAGE C VOLATILE;

CREATE LANGUAGE myLanguage
HANDLER myLanguage.myLanguage_function_call_handler
INLINE myLanguage.myLanguage_inline_function_handler;
COMMENT ON LANGUAGE myLanguage IS 'My Language';


Have I correctly approached the issue? Maybe there is a workaround?

Best regards
Tom

pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [PATCH][DOC] Fix for PREPARE TRANSACTION doc and postgres_fdwmessage.
Next
From: Andres Freund
Date:
Subject: Re: SPI error with non-volatile functions