Skip to content

Commit 41306a5

Browse files
committed
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 a61fd53. Repair. Also, make sure we cover the broken case in the relevant test script. Backpatch to 9.5. Discussion: https://postgr.es/m/[email protected]
1 parent 5feb78a commit 41306a5

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/backend/catalog/objectaddress.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1578,7 +1578,7 @@ get_object_address_opf_member(ObjectType objtype,
15781578
ObjectAddress address;
15791579
ListCell *cell;
15801580
List *copy;
1581-
char *typenames[2];
1581+
TypeName *typenames[2];
15821582
Oid typeoids[2];
15831583
int membernum;
15841584
int i;
@@ -1600,7 +1600,7 @@ get_object_address_opf_member(ObjectType objtype,
16001600
{
16011601
ObjectAddress typaddr;
16021602

1603-
typenames[i] = strVal(lfirst(cell));
1603+
typenames[i] = (TypeName *) lfirst(cell);
16041604
typaddr = get_object_address_type(OBJECT_TYPE, cell, missing_ok);
16051605
typeoids[i] = typaddr.objectId;
16061606
if (++i >= 2)
@@ -1627,7 +1627,9 @@ get_object_address_opf_member(ObjectType objtype,
16271627
ereport(ERROR,
16281628
(errcode(ERRCODE_UNDEFINED_OBJECT),
16291629
errmsg("operator %d (%s, %s) of %s does not exist",
1630-
membernum, typenames[0], typenames[1],
1630+
membernum,
1631+
TypeNameToString(typenames[0]),
1632+
TypeNameToString(typenames[1]),
16311633
getObjectDescription(&famaddr))));
16321634
}
16331635
else
@@ -1656,7 +1658,9 @@ get_object_address_opf_member(ObjectType objtype,
16561658
ereport(ERROR,
16571659
(errcode(ERRCODE_UNDEFINED_OBJECT),
16581660
errmsg("function %d (%s, %s) of %s does not exist",
1659-
membernum, typenames[0], typenames[1],
1661+
membernum,
1662+
TypeNameToString(typenames[0]),
1663+
TypeNameToString(typenames[1]),
16601664
getObjectDescription(&famaddr))));
16611665
}
16621666
else
@@ -1993,7 +1997,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
19931997
}
19941998

19951999
/*
1996-
* get_object_name is pretty sensitive to the length its input lists;
2000+
* get_object_address is pretty sensitive to the length its input lists;
19972001
* check that they're what it wants.
19982002
*/
19992003
switch (type)

src/test/regress/expected/object_address.out

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,15 @@ WARNING: error for sequence column: unsupported object type "sequence column"
6565
WARNING: error for toast table column: unsupported object type "toast table column"
6666
WARNING: error for view column: unsupported object type "view column"
6767
WARNING: error for materialized view column: unsupported object type "materialized view column"
68+
-- miscellaneous other errors
69+
select * from pg_get_object_address('operator of access method', '{btree,integer_ops,1}', '{int4,bool}');
70+
ERROR: operator 1 (int4, bool) of operator family integer_ops for access method btree does not exist
71+
select * from pg_get_object_address('operator of access method', '{btree,integer_ops,99}', '{int4,int4}');
72+
ERROR: operator 99 (int4, int4) of operator family integer_ops for access method btree does not exist
73+
select * from pg_get_object_address('function of access method', '{btree,integer_ops,1}', '{int4,bool}');
74+
ERROR: function 1 (int4, bool) of operator family integer_ops for access method btree does not exist
75+
select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}');
76+
ERROR: function 99 (int4, int4) of operator family integer_ops for access method btree does not exist
6877
DO $$
6978
DECLARE
7079
objtype text;

src/test/regress/sql/object_address.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ BEGIN
6262
END;
6363
$$;
6464

65+
-- miscellaneous other errors
66+
select * from pg_get_object_address('operator of access method', '{btree,integer_ops,1}', '{int4,bool}');
67+
select * from pg_get_object_address('operator of access method', '{btree,integer_ops,99}', '{int4,int4}');
68+
select * from pg_get_object_address('function of access method', '{btree,integer_ops,1}', '{int4,bool}');
69+
select * from pg_get_object_address('function of access method', '{btree,integer_ops,99}', '{int4,int4}');
70+
6571
DO $$
6672
DECLARE
6773
objtype text;

0 commit comments

Comments
 (0)