On Thu, Apr 14, 2011 at 11:23:49AM -0700, Robert Haas wrote:
> On Thu, Apr 14, 2011 at 5:18 AM, Noah Misch <[email protected]> wrote:
> >> I guess my gut feeling is that it would make more sense to forbid it
> >> outright for 9.1, and we can look at relaxing that restriction later
> >> if we're so inclined.
> >>
> >> Much as with the problem Tom fixed in commit
> >> eb51af71f241e8cb199790dee9ad246bb36b3287, I'm concerned that there may
> >> be other cases that we're not thinking of right now, and while we
> >> could find them all and fix them, the amount of functionality gained
> >> is fairly marginal, and I don't really want to hold up the release
> >> while we bug-swat.
> >
> > Symmetry was the best cause I could find to continue allowing it, and your
> > case
> > in favor of reducing the bug surface is more compelling. ?Let's forbid it.
>
> OK. Care to propose a patch?
Sure; attached. It requires that the type relation be RELKIND_COMPOSITE_TYPE.
We hadn't explicitly discussed the use of foreign table, view, toast table, or
sequence row types. The first two might have some value, someday; I'm sure
nobody cares for the second two.
nm
diff --git a/src/backend/parser/parse_utilcmd.c
b/src/backend/parser/parse_utilcmd.c
index eba890b..31b1fb0 100644
*** a/src/backend/parser/parse_utilcmd.c
--- b/src/backend/parser/parse_utilcmd.c
***************
*** 825,830 **** transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
--- 825,831 ----
TupleDesc tupdesc;
int i;
Oid ofTypeId;
+ bool typeOk = false;
AssertArg(ofTypename);
***************
*** 833,842 **** transformOfType(CreateStmtContext *cxt, TypeName *ofTypename)
ofTypeId = HeapTupleGetOid(tuple);
ofTypename->typeOid = ofTypeId; /* cached for later */
! if (typ->typtype != TYPTYPE_COMPOSITE)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
! errmsg("type %s is not a composite type",
format_type_be(ofTypeId))));
tupdesc = lookup_rowtype_tupdesc(ofTypeId, -1);
--- 834,852 ----
ofTypeId = HeapTupleGetOid(tuple);
ofTypename->typeOid = ofTypeId; /* cached for later */
! if (typ->typtype == TYPTYPE_COMPOSITE)
! {
! Relation typeRelation;
!
! Assert(OidIsValid(typ->typrelid));
! typeRelation = relation_open(typ->typrelid, AccessShareLock);
! typeOk = (typeRelation->rd_rel->relkind ==
RELKIND_COMPOSITE_TYPE);
! relation_close(typeRelation, NoLock);
! }
! if (!typeOk)
ereport(ERROR,
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
! errmsg("type %s is not a stand-alone composite
type",
format_type_be(ofTypeId))));
tupdesc = lookup_rowtype_tupdesc(ofTypeId, -1);
diff --git a/src/test/regress/expected/tyindex 0874a64..69ad58e 100644
*** a/src/test/regress/expected/typed_table.out
--- b/src/test/regress/expected/typed_table.out
***************
*** 91,96 **** DETAIL: drop cascades to table persons
--- 91,98 ----
drop cascades to function get_all_persons()
drop cascades to table persons2
drop cascades to table persons3
+ CREATE TABLE persons5 OF stuff; -- only CREATE TYPE AS types may be used
+ ERROR: type stuff is not a stand-alone composite type
DROP TABLE stuff;
-- implicit casting
CREATE TYPE person_type AS (id int, name text);
diff --git a/src/test/regress/sql/typed_table.sqindex b0d452c..25aaccb 100644
*** a/src/test/regress/sql/typed_table.sql
--- b/src/test/regress/sql/typed_table.sql
***************
*** 46,51 **** CREATE TABLE persons4 OF person_type (
--- 46,53 ----
DROP TYPE person_type RESTRICT;
DROP TYPE person_type CASCADE;
+ CREATE TABLE persons5 OF stuff; -- only CREATE TYPE AS types may be used
+
DROP TABLE stuff;
--
Sent via pgsql-hackers mailing list ([email protected])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers