aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlvaro Herrera <alvherre@alvh.no-ip.org>2017-03-16 12:51:08 -0300
committerAlvaro Herrera <alvherre@alvh.no-ip.org>2017-03-16 12:51:08 -0300
commita3eac988c26706059ae74c740a1abcb588449abe (patch)
tree592bd16b2bf19b3533a9ef412fa248e5aaaa174b
parentcccbddeb1483b85f1853a29dc3b6464647b91eee (diff)
downloadpostgresql-a3eac988c26706059ae74c740a1abcb588449abe.tar.gz
postgresql-a3eac988c26706059ae74c740a1abcb588449abe.zip
Fix ancient get_object_address_opf_member bug
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
-rw-r--r--src/backend/catalog/objectaddress.c18
-rw-r--r--src/test/regress/expected/object_address.out9
-rw-r--r--src/test/regress/sql/object_address.sql6
3 files changed, 26 insertions, 7 deletions
diff --git a/src/backend/catalog/objectaddress.c b/src/backend/catalog/objectaddress.c
index 3a7f0492472..61a831b4036 100644
--- a/src/backend/catalog/objectaddress.c
+++ b/src/backend/catalog/objectaddress.c
@@ -1552,7 +1552,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;
@@ -1574,8 +1574,8 @@ get_object_address_opf_member(ObjectType objtype,
{
ObjectAddress typaddr;
- typenames[i] = strVal(lfirst(cell));
- typaddr = get_object_address_type(OBJECT_TYPE, castNode(TypeName, lfirst(cell)), missing_ok);
+ typenames[i] = castNode(TypeName, lfirst(cell));
+ typaddr = get_object_address_type(OBJECT_TYPE, typenames[i], missing_ok);
typeoids[i] = typaddr.objectId;
if (++i >= 2)
break;
@@ -1601,7 +1601,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
@@ -1630,7 +1632,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
@@ -2023,7 +2027,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)
@@ -2064,7 +2068,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
}
/*
- * Now build the Node type that get_object_name() expects for the given
+ * Now build the Node type that get_object_address() expects for the given
* type.
*/
switch (type)
diff --git a/src/test/regress/expected/object_address.out b/src/test/regress/expected/object_address.out
index 836773f9e44..90c4ba4608d 100644
--- a/src/test/regress/expected/object_address.out
+++ b/src/test/regress/expected/object_address.out
@@ -67,6 +67,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;
diff --git a/src/test/regress/sql/object_address.sql b/src/test/regress/sql/object_address.sql
index 0ace4dd4255..6b85fe29497 100644
--- a/src/test/regress/sql/object_address.sql
+++ b/src/test/regress/sql/object_address.sql
@@ -64,6 +64,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;