From: Itagaki Takahiro <itagaki.takahiro@gmail.com>
Date: Tue, 28 Sep 2010 06:56:46 +0000 (+0900)
Subject: Only DISCARD ALL should be in the command_no_begin list.
X-Git-Tag: REL9_0_1~16
X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=279ab82791ebcb09442a599a74c641c5c5255dbf;p=postgresql

Only DISCARD ALL should be in the command_no_begin list.
We allowes DISCARD PLANS and TEMP in a transaction.
---

diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 4027f77be2..72115f8ae6 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -1388,8 +1388,20 @@ command_no_begin(const char *query)
 			return true;
 	}
 
+	/* DISCARD ALL isn't allowed in xacts, but other variants are allowed. */
 	if (wordlen == 7 && pg_strncasecmp(query, "discard", 7) == 0)
-		return true;
+	{
+		query += wordlen;
+
+		query = skip_white_space(query);
+
+		wordlen = 0;
+		while (isalpha((unsigned char) query[wordlen]))
+			wordlen += PQmblen(&query[wordlen], pset.encoding);
+
+		if (wordlen == 3 && pg_strncasecmp(query, "all", 3) == 0)
+			return true;
+	}
 
 	return false;
 }