mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Issue error on SET outside transaction block in some cases
Issue error for SET LOCAL/CONSTRAINTS/TRANSACTION outside a transaction block, as they have no effect. Per suggestion from Morten Hustveit
This commit is contained in:
@ -6252,7 +6252,7 @@ flatten_set_variable_args(const char *name, List *args)
|
||||
* SET command
|
||||
*/
|
||||
void
|
||||
ExecSetVariableStmt(VariableSetStmt *stmt)
|
||||
ExecSetVariableStmt(VariableSetStmt *stmt, bool isTopLevel)
|
||||
{
|
||||
GucAction action = stmt->is_local ? GUC_ACTION_LOCAL : GUC_ACTION_SET;
|
||||
|
||||
@ -6260,6 +6260,8 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
|
||||
{
|
||||
case VAR_SET_VALUE:
|
||||
case VAR_SET_CURRENT:
|
||||
if (stmt->is_local)
|
||||
RequireTransactionChain(isTopLevel, "SET LOCAL");
|
||||
(void) set_config_option(stmt->name,
|
||||
ExtractSetVariableArgs(stmt),
|
||||
(superuser() ? PGC_SUSET : PGC_USERSET),
|
||||
@ -6269,7 +6271,6 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
|
||||
0);
|
||||
break;
|
||||
case VAR_SET_MULTI:
|
||||
|
||||
/*
|
||||
* Special-case SQL syntaxes. The TRANSACTION and SESSION
|
||||
* CHARACTERISTICS cases effectively set more than one variable
|
||||
@ -6281,6 +6282,8 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
|
||||
{
|
||||
ListCell *head;
|
||||
|
||||
RequireTransactionChain(isTopLevel, "SET TRANSACTION");
|
||||
|
||||
foreach(head, stmt->args)
|
||||
{
|
||||
DefElem *item = (DefElem *) lfirst(head);
|
||||
@ -6329,6 +6332,8 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("SET LOCAL TRANSACTION SNAPSHOT is not implemented")));
|
||||
|
||||
RequireTransactionChain(isTopLevel, "SET TRANSACTION");
|
||||
Assert(IsA(con, A_Const));
|
||||
Assert(nodeTag(&con->val) == T_String);
|
||||
ImportSnapshot(strVal(&con->val));
|
||||
@ -6338,7 +6343,13 @@ ExecSetVariableStmt(VariableSetStmt *stmt)
|
||||
stmt->name);
|
||||
break;
|
||||
case VAR_SET_DEFAULT:
|
||||
if (stmt->is_local)
|
||||
RequireTransactionChain(isTopLevel, "SET LOCAL");
|
||||
/* fall through */
|
||||
case VAR_RESET:
|
||||
if (strcmp(stmt->name, "transaction_isolation") == 0)
|
||||
RequireTransactionChain(isTopLevel, "RESET TRANSACTION");
|
||||
|
||||
(void) set_config_option(stmt->name,
|
||||
NULL,
|
||||
(superuser() ? PGC_SUSET : PGC_USERSET),
|
||||
|
Reference in New Issue
Block a user