SPI error with non-volatile functions

From: Tom Mercha <mercha_t(at)hotmail(dot)com>
To: "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: SPI error with non-volatile functions
Date: 2019-11-13 05:09:31
Message-ID: VI1PR02MB37123D4AF993B4288A395652F4760@VI1PR02MB3712.eurprd02.prod.outlook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2019-11-13 05:13:59 Re: SPI error with non-volatile functions
Previous Message Michael Paquier 2019-11-13 04:53:24 Re: [PATCH][DOC] Fix for PREPARE TRANSACTION doc and postgres_fdw message.