From 7d60b2af34842ae89b1abdd31fb5d303bd43c514 Mon Sep 17 00:00:00 2001
From: Alvaro Herrera <alvherre@alvh.no-ip.org>
Date: Fri, 26 Jun 2015 18:17:54 -0300
Subject: [PATCH] Fix DDL command collection for TRANSFORM

Commit b488c580ae, which added the DDL command collection feature,
neglected to update the code that commit cac76582053e had previously
added two weeks earlier for the TRANSFORM feature.

Reported by Michael Paquier.
---
 src/backend/commands/functioncmds.c                |  4 ++--
 src/backend/tcop/utility.c                         |  2 +-
 src/include/commands/defrem.h                      |  2 +-
 src/test/modules/test_ddl_deparse/Makefile         |  1 +
 .../test_ddl_deparse/expected/create_transform.out | 13 +++++++++++++
 .../test_ddl_deparse/sql/create_transform.sql      | 14 ++++++++++++++
 6 files changed, 32 insertions(+), 4 deletions(-)
 create mode 100644 src/test/modules/test_ddl_deparse/expected/create_transform.out
 create mode 100644 src/test/modules/test_ddl_deparse/sql/create_transform.sql

diff --git a/src/backend/commands/functioncmds.c b/src/backend/commands/functioncmds.c
index 4accf767bbf..dbbb2d3f88a 100644
--- a/src/backend/commands/functioncmds.c
+++ b/src/backend/commands/functioncmds.c
@@ -1740,7 +1740,7 @@ check_transform_function(Form_pg_proc procstruct)
 /*
  * CREATE TRANSFORM
  */
-Oid
+ObjectAddress
 CreateTransform(CreateTransformStmt *stmt)
 {
 	Oid			typeid;
@@ -1938,7 +1938,7 @@ CreateTransform(CreateTransformStmt *stmt)
 
 	heap_close(relation, RowExclusiveLock);
 
-	return transformid;
+	return myself;
 }
 
 
diff --git a/src/backend/tcop/utility.c b/src/backend/tcop/utility.c
index 7db9f96fdf7..0dabcc130e0 100644
--- a/src/backend/tcop/utility.c
+++ b/src/backend/tcop/utility.c
@@ -1438,7 +1438,7 @@ ProcessUtilitySlow(Node *parsetree,
 				break;
 
 			case T_CreateTransformStmt:
-				CreateTransform((CreateTransformStmt *) parsetree);
+				address = CreateTransform((CreateTransformStmt *) parsetree);
 				break;
 
 			case T_AlterOpFamilyStmt:
diff --git a/src/include/commands/defrem.h b/src/include/commands/defrem.h
index dcb6c082c52..9b81c16d823 100644
--- a/src/include/commands/defrem.h
+++ b/src/include/commands/defrem.h
@@ -51,7 +51,7 @@ extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
 extern ObjectAddress AlterFunction(AlterFunctionStmt *stmt);
 extern ObjectAddress CreateCast(CreateCastStmt *stmt);
 extern void DropCastById(Oid castOid);
-extern Oid	CreateTransform(CreateTransformStmt *stmt);
+extern ObjectAddress CreateTransform(CreateTransformStmt *stmt);
 extern void DropTransformById(Oid transformOid);
 extern void IsThereFunctionInNamespace(const char *proname, int pronargs,
 						   oidvector *proargtypes, Oid nspOid);
diff --git a/src/test/modules/test_ddl_deparse/Makefile b/src/test/modules/test_ddl_deparse/Makefile
index 13b985a2963..8ea6f39afd2 100644
--- a/src/test/modules/test_ddl_deparse/Makefile
+++ b/src/test/modules/test_ddl_deparse/Makefile
@@ -15,6 +15,7 @@ REGRESS = test_ddl_deparse \
 	create_domain \
 	create_sequence_1 \
 	create_table \
+	create_transform \
 	alter_table \
 	create_view \
 	create_trigger \
diff --git a/src/test/modules/test_ddl_deparse/expected/create_transform.out b/src/test/modules/test_ddl_deparse/expected/create_transform.out
new file mode 100644
index 00000000000..0d1cc360f4e
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/expected/create_transform.out
@@ -0,0 +1,13 @@
+--
+-- CREATE_TRANSFORM
+--
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+    FROM SQL WITH FUNCTION varchar_transform(internal),
+    TO SQL WITH FUNCTION int4recv(internal));
+NOTICE:  DDL test: type simple, tag CREATE TRANSFORM
+DROP TRANSFORM FOR int LANGUAGE SQL;
diff --git a/src/test/modules/test_ddl_deparse/sql/create_transform.sql b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
new file mode 100644
index 00000000000..096870233f8
--- /dev/null
+++ b/src/test/modules/test_ddl_deparse/sql/create_transform.sql
@@ -0,0 +1,14 @@
+--
+-- CREATE_TRANSFORM
+--
+
+-- Create a dummy transform
+-- The function FROM SQL should have internal as single argument as well
+-- as return type. The function TO SQL should have as single argument
+-- internal and as return argument the datatype of the transform done.
+-- pl/plpgsql does not authorize the use of internal as data type.
+CREATE TRANSFORM FOR int LANGUAGE SQL (
+    FROM SQL WITH FUNCTION varchar_transform(internal),
+    TO SQL WITH FUNCTION int4recv(internal));
+
+DROP TRANSFORM FOR int LANGUAGE SQL;
-- 
GitLab