Skip to content

Commit 95a615f

Browse files
committed
Fix INSERT EXEC with OUTPUT parameters
When a procedure with OUTPUT parameters is called via INSERT EXEC: 1. The OUTPUT parameter values should be returned to the caller variable 2. Only the SELECT results should be inserted into the target table 3. The OUTPUT parameter values should NOT be inserted into the table The fix involves two key changes: 1. Copy OUTPUT parameter values to TopTransactionContext instead of the procedure's fn_cxt. The fn_cxt gets freed when the procedure returns, causing memory corruption (OID 0x7F7F7F7F error). 2. Set fcinfo->isnull = true to prevent the OUTPUT parameter values from being sent to the client/destination (which would insert them into the table). The new is_insert_exec_rewrite_active_hook in functioncmds.c allows this without causing 'procedure returned null record' error. 3. Register the hook in pl_handler.c to enable the INSERT EXEC context detection in PostgreSQL core. This matches SQL Server behavior where OUTPUT parameters are returned to caller variables but not inserted into the target table.
1 parent 8439adb commit 95a615f

File tree

2 files changed

+260
-70
lines changed

2 files changed

+260
-70
lines changed

0 commit comments

Comments
 (0)