Skip to content

Commit fecaf33

Browse files
committed
Allow ALTER EXTENSION UPDATE inside a transaction block
Opening a transaction with BEGIN or START TRANSACTION used to load the extension. That made ALTER EXTENSION timescaledb UPDATE fail inside a transaction block because the old version was already loaded before the update ran. The loader now skips loading on BEGIN and START TRANSACTION, so the update can run as the first extension command in the transaction.
1 parent 68820ea commit fecaf33

5 files changed

Lines changed: 105 additions & 144 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixes: #10313 Allow running ALTER EXTENSION timescaledb UPDATE inside a transaction block

src/loader/loader.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,27 @@ should_load_on_create_extension(Node const *const utility_stmt, TsExtension cons
392392
return false;
393393
}
394394

395+
static bool
396+
should_load_on_transaction(Node const *const utility_stmt, TsExtension const *const /*ext*/)
397+
{
398+
TransactionStmt *stmt = (TransactionStmt *) utility_stmt;
399+
400+
/*
401+
* Do not load the extension just to open a transaction. This lets ALTER
402+
* EXTENSION ... UPDATE run as the first extension-touching command inside
403+
* a transaction block instead of failing because BEGIN already loaded the
404+
* old version.
405+
*/
406+
switch (stmt->kind)
407+
{
408+
case TRANS_STMT_BEGIN:
409+
case TRANS_STMT_START:
410+
return false;
411+
default:
412+
return true;
413+
}
414+
}
415+
395416
static bool
396417
load_utility_cmd(Node const *const utility_stmt, TsExtension const *const ext)
397418
{
@@ -403,6 +424,8 @@ load_utility_cmd(Node const *const utility_stmt, TsExtension const *const ext)
403424
return should_load_on_alter_extension(utility_stmt, ext);
404425
case T_CreateExtensionStmt:
405426
return should_load_on_create_extension(utility_stmt, ext);
427+
case T_TransactionStmt:
428+
return should_load_on_transaction(utility_stmt, ext);
406429
case T_DropStmt:
407430
return !drop_statement_drops_extension((DropStmt *) utility_stmt, ext);
408431
default:

0 commit comments

Comments
 (0)