Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 5520006

Browse files
committed
Prevent psql from issuing BEGIN before ALTER SYSTEM when AUTOCOMMIT is off.
The autocommit-off mode works by issuing an implicit BEGIN just before any command that is not already in a transaction block and is not itself a BEGIN or other transaction-control command, nor a command that cannot be executed inside a transaction block. This commit prevents psql from issuing such an implicit BEGIN before ALTER SYSTEM because it's not allowed inside a transaction block. Backpatch to 9.4 where ALTER SYSTEM was added. Report by Feike Steenbergen
1 parent 49bca9e commit 5520006

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/bin/psql/common.c

+17
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,23 @@ command_no_begin(const char *query)
15241524
return false;
15251525
}
15261526

1527+
if (wordlen == 5 && pg_strncasecmp(query, "alter", 5) == 0)
1528+
{
1529+
query += wordlen;
1530+
1531+
query = skip_white_space(query);
1532+
1533+
wordlen = 0;
1534+
while (isalpha((unsigned char) query[wordlen]))
1535+
wordlen += PQmblen(&query[wordlen], pset.encoding);
1536+
1537+
/* ALTER SYSTEM isn't allowed in xacts */
1538+
if (wordlen == 6 && pg_strncasecmp(query, "system", 6) == 0)
1539+
return true;
1540+
1541+
return false;
1542+
}
1543+
15271544
/*
15281545
* Note: these tests will match DROP SYSTEM and REINDEX TABLESPACE, which
15291546
* aren't really valid commands so we don't care much. The other four

0 commit comments

Comments
 (0)