]> granicus.if.org Git - postgresql/commitdiff
Fix ancient get_object_address_opf_member bug
authorAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 16 Mar 2017 15:51:08 +0000 (12:51 -0300)
committerAlvaro Herrera <alvherre@alvh.no-ip.org>
Thu, 16 Mar 2017 15:51:08 +0000 (12:51 -0300)
The original coding was trying to use a TypeName as a string Value,
which doesn't work; an oversight in my commit a61fd533.  Repair.

Also, make sure we cover the broken case in the relevant test script.

Backpatch to 9.5.

Discussion: https://postgr.es/m/20170315151829.bhxsvrp75xdxhm3n@alvherre.pgsql

src/backend/catalog/objectaddress.c
src/test/regress/expected/object_address.out
src/test/regress/sql/object_address.sql

index da370fc25933d10035d22fd1b05324c56fbdae68..c8ddb540f69253be1c5749ce0eec35e217e5b887 100644 (file)
@@ -1526,7 +1526,7 @@ get_object_address_opf_member(ObjectType objtype,
        ObjectAddress address;
        ListCell   *cell;
        List       *copy;
-       char       *typenames[2];
+       TypeName   *typenames[2];
        Oid                     typeoids[2];
        int                     membernum;
        int                     i;
@@ -1548,7 +1548,7 @@ get_object_address_opf_member(ObjectType objtype,
        {
                ObjectAddress typaddr;
 
-               typenames[i] = strVal(lfirst(cell));
+               typenames[i] = (TypeName *) lfirst(cell);
                typaddr = get_object_address_type(OBJECT_TYPE, cell, missing_ok);
                typeoids[i] = typaddr.objectId;
                if (++i >= 2)
@@ -1575,7 +1575,9 @@ get_object_address_opf_member(ObjectType objtype,
                                                ereport(ERROR,
                                                                (errcode(ERRCODE_UNDEFINED_OBJECT),
                                                  errmsg("operator %d (%s, %s) of %s does not exist",
-                                                                membernum, typenames[0], typenames[1],
+                                                                membernum,
+                                                                TypeNameToString(typenames[0]),
+                                                                TypeNameToString(typenames[1]),
                                                                 getObjectDescription(&famaddr))));
                                }
                                else
@@ -1604,7 +1606,9 @@ get_object_address_opf_member(ObjectType objtype,
                                                ereport(ERROR,
                                                                (errcode(ERRCODE_UNDEFINED_OBJECT),
                                                  errmsg("function %d (%s, %s) of %s does not exist",
-                                                                membernum, typenames[0], typenames[1],
+                                                                membernum,
+                                                                TypeNameToString(typenames[0]),
+                                                                TypeNameToString(typenames[1]),
                                                                 getObjectDescription(&famaddr))));
                                }
                                else
@@ -1941,7 +1945,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
        }
 
        /*
-        * get_object_name is pretty sensitive to the length its input lists;
+        * get_object_address is pretty sensitive to the length its input lists;
         * check that they're what it wants.
         */
        switch (type)
index 75751bebeff157d21297592d201b73fd19b2739b..191d2fb6fdcf6977f26a413b2e55c0bff8a01d91 100644 (file)
@@ -64,6 +64,15 @@ WARNING:  error for sequence column: unsupported object type "sequence column"
 WARNING:  error for toast table column: unsupported object type "toast table column"
 WARNING:  error for view column: unsupported object type "view column"
 WARNING:  error for materialized view column: unsupported object type "materialized view column"
+-- miscellaneous other errors
+select * from pg_get_object_address('operator of access method', '{btree,integer_ops,1}', '{int4,bool}');
+ERROR:  operator 1 (int4, bool) of operator family integer_ops for access method btree does not exist
+select * from pg_get_object_address('operator of access method', '{btree,integer_ops,99}', '{int4,int4}');
+ERROR:  operator 99 (int4, int4) of operator family integer_ops for access method btree does not exist
+select * from pg_get_object_address('function of access method', '{btree,integer_ops,1}', '{int4,bool}');
+ERROR:  function 1 (int4, bool) of operator family integer_ops for access method btree does not exist
+select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}');
+ERROR:  function 99 (int4, int4) of operator family integer_ops for access method btree does not exist
 DO $$
 DECLARE
        objtype text;
index 68e7cb0eb3a55c66dd6b39b3f46afffa17da95de..3e792ef849c1f431f3c6b85a13fb44835781ca08 100644 (file)
@@ -62,6 +62,12 @@ BEGIN
 END;
 $$;
 
+-- miscellaneous other errors
+select * from pg_get_object_address('operator of access method', '{btree,integer_ops,1}', '{int4,bool}');
+select * from pg_get_object_address('operator of access method', '{btree,integer_ops,99}', '{int4,int4}');
+select * from pg_get_object_address('function of access method', '{btree,integer_ops,1}', '{int4,bool}');
+select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}');
+
 DO $$
 DECLARE
        objtype text;