Skip to content

Conversation

dpxcc
Copy link
Contributor

@dpxcc dpxcc commented Aug 9, 2025

DuckDB execution inside functions was disallowed in #764 for good reason
However, some users depend on running analytics with pg_duckdb inside functions

Given that (1) the problematic cases are rare, and (2) pg_duckdb is mostly used for read queries, failures are limited to crashing the current session and can be recovered by restarting the session without data loss. This change introduces an unsafe GUC to restore this capability for users who need it

@dpxcc dpxcc marked this pull request as ready for review August 9, 2025 22:50
@@ -143,6 +144,9 @@ InitGUC() {
/* pg_duckdb specific GUCs */
DefineCustomVariable("duckdb.force_execution", "Force queries to use DuckDB execution", &duckdb_force_execution);

DefineCustomVariable("duckdb.unsafe_allow_execution_inside_functions", "Allow DuckDB execution inside functions",
&duckdb_unsafe_allow_execution_inside_functions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that this can introduce crashes I think a superuser should be configuring this.

Suggested change
&duckdb_unsafe_allow_execution_inside_functions);
&duckdb_unsafe_allow_execution_inside_functions, 0, GUC_SUPERUSER_ONLY);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. But did you mean

	                     &duckdb_unsafe_allow_execution_inside_functions, PGC_SUSET);

instead?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's definitely what I meant. After many years I still keep confusing these two.

@@ -117,9 +118,8 @@ $$;
-- After executing the function the table should not contain the value 8,
-- because that change was rolled back
SELECT * FROM f(true);
ERROR: DuckDB execution is not supported inside functions
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still have some tests for the default behaviour?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JelteF JelteF merged commit 8152aa4 into duckdb:main Aug 15, 2025
7 checks passed
@dpxcc dpxcc deleted the allow_execution_inside_functions branch August 16, 2025 01:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants