When we added the ability to have zero-element ARRAY[] constructs by adding an
authorTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Dec 2008 05:04:35 +0000 (05:04 +0000)
committerTom Lane <tgl@sss.pgh.pa.us>
Fri, 19 Dec 2008 05:04:35 +0000 (05:04 +0000)
explicit cast to show the intended array type, we forgot to teach ruleutils.c
to print out such constructs properly.  Found by noting bogus output from
recent changes in polymorphism regression test.

src/backend/utils/adt/ruleutils.c
src/test/regress/expected/polymorphism.out

index 0d2fc894bc3159b69430a373be4b67f59862eb2f..6d003ac662f6bdd33c8a128840d6df7ccd0a187e 100644 (file)
@@ -4451,6 +4451,14 @@ get_rule_expr(Node *node, deparse_context *context,
                                appendStringInfo(buf, "ARRAY[");
                                get_rule_expr((Node *) arrayexpr->elements, context, true);
                                appendStringInfoChar(buf, ']');
+                               /*
+                                * If the array isn't empty, we assume its elements are
+                                * coerced to the desired type.  If it's empty, though, we
+                                * need an explicit coercion to the array type.
+                                */
+                               if (arrayexpr->elements == NIL)
+                                       appendStringInfo(buf, "::%s",
+                                               format_type_with_typemod(arrayexpr->array_typeid, -1));
                        }
                        break;
 
index 6fafc0343cc2cb32a1f916b1d511bf4cae10d773..aace99cb62554bee87ccecc95c414974c0c32749 100644 (file)
@@ -1005,10 +1005,10 @@ $$ select array_upper($1, 1) $$ language sql;
 ERROR:  cannot remove parameter defaults from existing function
 HINT:  Use DROP FUNCTION first.
 \df dfunc
-                            List of functions
- Schema | Name  | Result data type |         Argument data types          
---------+-------+------------------+--------------------------------------
- public | dfunc | integer          | VARIADIC a integer[] DEFAULT ARRAY[]
+                                  List of functions
+ Schema | Name  | Result data type |               Argument data types               
+--------+-------+------------------+-------------------------------------------------
+ public | dfunc | integer          | VARIADIC a integer[] DEFAULT ARRAY[]::integer[]
 (1 row)
 
 drop function dfunc(a variadic int[]);