On Friday, October 19, 2012 06:41:27 PM Peter Geoghegan wrote:
> On 19 October 2012 17:19, Robert Haas <robertmh...@gmail.com> wrote:
> > Rushabh Lathia of the EnterpriseDB development team and I have been
> > doing some testing of the extended query protocol and have found a
> > case where it causes an assertion failure.  Here's how to reproduce:
> > 
> > 1. Apply the attached patch to teach psql how to use the extended
> > query protocol.  Compile, install.
> > 
> > 2. Start the modified psql and do this:
> > 
> > \set PROTOCOL extended
> > PREPARE stmt as select 1;
> > CREATE TEMPORARY TABLE tmptbl AS EXECUTE stmt;
> > 
> > The result is:
> > 
> > TRAP: FailedAssertion("!(qry->commandType != CMD_UTILITY)", File:
> > "utility.c", Line: 1516)f
> 
> I'm reasonably confident that commit
> 9dbf2b7d75de5af38d087cbe2b1147dd0fd10f0a caused this breakage.

Simple fix attached. 

Btw, do you plan to submit that psql patch at some point? I repeatedly wished 
to be able to use the extended protocol without writing code or misusing 
pgbench exactly to test stuff like this.

Greetings,

Andres
-- 
Andres Freund           http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
From 434ce09ecae207a1f128eec5593f667b8507f220 Mon Sep 17 00:00:00 2001
From: Andres Freund <and...@anarazel.de>
Date: Fri, 19 Oct 2012 19:40:49 +0200
Subject: [PATCH] Fix simple oversight causing UtilityContainsQuery not to
 support CREATE TABLE AS ... EXECUTE

UtilityContainsQuery looked in CreateTableAsStmt->query for an ExecuteStmt but
transformCreateTableAsStmt always puts it in ->query->utilityStmt.
---
 src/backend/tcop/utility.c |   19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 97376bb..0d1af0b 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1508,17 +1508,20 @@ UtilityContainsQuery(Node *parsetree)
 			return qry;
 
 		case T_CreateTableAsStmt:
-			/* might or might not contain a Query ... */
 			qry = (Query *) ((CreateTableAsStmt *) parsetree)->query;
-			if (IsA(qry, Query))
-			{
-				/* Recursion currently can't be necessary here */
-				Assert(qry->commandType != CMD_UTILITY);
+			Assert(IsA(qry, Query));
+
+			/* CREATE TABLE .. EXECUTE ...*/
+			if (qry->commandType == CMD_UTILITY &&
+			    IsA(qry->utilityStmt, ExecuteStmt))
+				return NULL;
+			/* CREATE TABLE .. SELECT ... */
+			else if (qry->commandType == CMD_SELECT)
 				return qry;
-			}
-			Assert(IsA(qry, ExecuteStmt));
-			return NULL;
 
+			/* Recursion currently can't be necessary here */
+			elog(ERROR, "unsupported case in CREATE TABLE AS");
+			return NULL; /* silence compiler */
 		default:
 			return NULL;
 	}
-- 
1.7.10.4

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers

Reply via email to