Commit fc769589 authored by Tom Lane's avatar Tom Lane

Prevent a rowtype from being included in itself via a range.

We probably should have thought of this case when ranges were added,
but we didn't.  (It's not the fault of commit eb51af71, because
ranges didn't exist then.)

It's an old bug, so back-patch to all supported branches.

Discussion: https://postgr.es/m/7782.1577051475@sss.pgh.pa.us
parent 0fd8cfb2
...@@ -655,6 +655,15 @@ CheckAttributeType(const char *attname, ...@@ -655,6 +655,15 @@ CheckAttributeType(const char *attname,
containing_rowtypes = list_delete_last(containing_rowtypes); containing_rowtypes = list_delete_last(containing_rowtypes);
} }
else if (att_typtype == TYPTYPE_RANGE)
{
/*
* If it's a range, recurse to check its subtype.
*/
CheckAttributeType(attname, get_range_subtype(atttypid), attcollation,
containing_rowtypes,
flags);
}
else if (OidIsValid((att_typelem = get_element_type(atttypid)))) else if (OidIsValid((att_typelem = get_element_type(atttypid))))
{ {
/* /*
......
...@@ -1375,6 +1375,9 @@ select *, row_to_json(upper(t)) as u from ...@@ -1375,6 +1375,9 @@ select *, row_to_json(upper(t)) as u from
["(5,6)","(7,8)") | {"a":7,"b":8} ["(5,6)","(7,8)") | {"a":7,"b":8}
(2 rows) (2 rows)
-- this must be rejected to avoid self-inclusion issues:
alter type two_ints add attribute c two_ints_range;
ERROR: composite type two_ints cannot be made a member of itself
drop type two_ints cascade; drop type two_ints cascade;
NOTICE: drop cascades to type two_ints_range NOTICE: drop cascades to type two_ints_range
-- --
......
...@@ -463,6 +463,9 @@ select *, row_to_json(upper(t)) as u from ...@@ -463,6 +463,9 @@ select *, row_to_json(upper(t)) as u from
(values (two_ints_range(row(1,2), row(3,4))), (values (two_ints_range(row(1,2), row(3,4))),
(two_ints_range(row(5,6), row(7,8)))) v(t); (two_ints_range(row(5,6), row(7,8)))) v(t);
-- this must be rejected to avoid self-inclusion issues:
alter type two_ints add attribute c two_ints_range;
drop type two_ints cascade; drop type two_ints cascade;
-- --
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment