8000 Fix ancient get_object_address_opf_member bug · thatguystone/postgres@087e696 · GitHub
[go: up one dir, main page]

Skip to content

Commit 087e696

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/20170315151829.bhxsvrp75xdxhm3n@alvherre.pgsql
1 parent 5adec6b commit 087e696

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
@@ -1526,7 +1526,7 @@ get_object_address_opf_member(ObjectType objtype,
15261526
ObjectAddress address;
15271527
ListCell *cell;
15281528
List *copy;
1529-
char *typenames[2];
1529+
TypeName *typenames[2];
15301530
Oid typeoids[2];
15311531
int membernum;
15321532
int i;
@@ -1548,7 +1548,7 @@ get_object_address_opf_member(ObjectType objtype,
15481548
{
15491549
ObjectAddress typaddr;
15501550

1551-
typenames[i] = strVal(lfirst(cell));
1551+
typenames[i] = (TypeName *) lfirst(cell);
15521552
typaddr = get_object_address_type(OBJECT_TYPE, cell, missing_ok);
15531553
typeoids[i] = typaddr.objectId;
15541554
if (++i >= 2)
@@ -1575,7 +1575,9 @@ get_object_address_opf_member(ObjectType objtype,
15751575
ereport(ERROR,
15761576
(errcode(ERRCODE_UNDEFINED_OBJECT),
15771577
errmsg("operator %d (%s, %s) of %s does not exist",
1578-
membernum, typenames[0], typenames[1],
1578+
membernum,
1579+
TypeNameToString(typenames[0]),
1580+
TypeNameToString(typenames[1]),
15791581
getObjectDescription(&famaddr))));
15801582
}
15811583
else
@@ -1604,7 +1606,9 @@ get_object_address_opf_member(ObjectType objtype,
16041606
ereport(ERROR,
16051607
(errcode(ERRCODE_UNDEFINED_OBJECT),
16061608
errmsg("function %d (%s, %s) of %s does not exist",
1607-
membernum, typenames[0], typenames[1],
1609+
membernum,
1610+
TypeNameToString(typenames[0]),
1611+
TypeNameToString(typenames[1]),
16081612
getObjectDescription(&famaddr))));
16091613
}
16101614
else
@@ -1941,7 +1945,7 @@ pg_get_object_address(PG_FUNCTION_ARGS)
19411945
}
19421946

19431947
/*
1944-
* get_object_name is pretty sensitive to the length its input lists;
1948+
* get_object_address is pretty sensitive to the length its input lists;
19451949
* check that they're what it wants.
19461950
*/
19471951
switch (type)

src/test/regress/expected/object_address.out

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