On Mon, May 18, 2015 at 2:09 PM, Peter Geoghegan <p...@heroku.com> wrote:
> You pointed out that the reason for this trivial bug on Jabber, but
> here's the obvious fix, including an EXPLAIN regression test.

Also, I attach a patch adding ruleutils.c deparsing support for INSERT
statement target aliases. This was previously overlooked.

-- 
Peter Geoghegan
From baaa50e2c5316ec1b4b0f1d0a9defb941ad8dbe8 Mon Sep 17 00:00:00 2001
From: Peter Geoghegan <peter.geoghega...@gmail.com>
Date: Mon, 18 May 2015 19:01:20 -0700
Subject: [PATCH 3/3] Deparsing support for INSERT AS alias

Now that ON CONFLICT DO UPDATE has established that INSERT targets may
accept an alias, have ruleutils.c perform the appropriate deparsing.
---
 src/backend/utils/adt/ruleutils.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index b54d508..a32a021 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -5392,6 +5392,10 @@ get_insert_query_def(Query *query, deparse_context *context)
 	}
 	appendStringInfo(buf, "INSERT INTO %s ",
 					 generate_relation_name(rte->relid, NIL));
+	/* INSERT requires AS keyword for target alias */
+	if (rte->alias != NULL)
+		appendStringInfo(buf, " AS %s",
+						 quote_identifier(rte->alias->aliasname));
 
 	/*
 	 * Add the insert-column-names list.  To handle indirection properly, we
-- 
1.9.1

-- 
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