From e6f43c35ae8d705745895e3284a1a83ce965307a Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Sat, 14 Feb 2015 15:38:28 -0300
Subject: [PATCH 37/44] deparse: support REFRESH MATERIALIZED VIEW

---
 src/backend/tcop/deparse_utility.c | 27 ++++++++++++++++++++++++++-
 1 file changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/backend/tcop/deparse_utility.c b/src/backend/tcop/deparse_utility.c
index 6882261..18fdd10 100644
--- a/src/backend/tcop/deparse_utility.c
+++ b/src/backend/tcop/deparse_utility.c
@@ -2006,6 +2006,31 @@ deparse_CreateTrigStmt(Oid objectId, Node *parsetree)
 	return trigger;
 }
 
+static ObjTree *
+deparse_RefreshMatViewStmt(Oid objectId, Node *parsetree)
+{
+	RefreshMatViewStmt *node = (RefreshMatViewStmt *) parsetree;
+	ObjTree	   *refreshStmt;
+	ObjTree	   *tmp;
+
+	refreshStmt = new_objtree_VA("REFRESH MATERIALIZED VIEW %{concurrently}s %{identity}D "
+								 "%{with_no_data}s", 0);
+	/* add a CONCURRENTLY clause */
+	append_string_object(refreshStmt, "concurrently",
+						 node->concurrent ? "CONCURRENTLY" : "");
+	/* add the matview name */
+	append_object_object(refreshStmt, "identity",
+						 new_objtree_for_qualname_id(RelationRelationId,
+													 objectId));
+	/* add a WITH NO DATA clause */
+	tmp = new_objtree_VA("WITH NO DATA", 1,
+						 "present", ObjTypeBool,
+						 node->skipData ? true : false);
+	append_object_object(refreshStmt, "with_no_data", tmp);
+
+	return refreshStmt;
+}
+
 /*
  * deparse_ColumnDef
  *		Subroutine for CREATE TABLE deparsing
@@ -5564,7 +5589,7 @@ deparse_simple_command(StashedCommand *cmd)
 			break;
 
 		case T_RefreshMatViewStmt:
-			elog(ERROR, "unimplemented deparse of %s", CreateCommandTag(parsetree));
+			command = deparse_RefreshMatViewStmt(objectId, parsetree);
 			break;
 
 		case T_CreateTrigStmt:
-- 
2.1.4

