88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.86 2003/08/04 02:40:03 momjian Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteDefine.c,v 1.87 2003/09/17 17:19:17 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -392,7 +392,8 @@ DefineQueryRewrite(RuleStmt *stmt)
392392 * Are we converting a relation to a view?
393393 *
394394 * If so, check that the relation is empty because the storage for
395- * the relation is going to be deleted.
395+ * the relation is going to be deleted. Also insist that the rel
396+ * not have any triggers, indexes, or child tables.
396397 */
397398 if (event_relation -> rd_rel -> relkind != RELKIND_VIEW )
398399 {
@@ -402,10 +403,29 @@ DefineQueryRewrite(RuleStmt *stmt)
402403 if (heap_getnext (scanDesc , ForwardScanDirection ) != NULL )
403404 ereport (ERROR ,
404405 (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
405- errmsg ("cannot convert non-empty table \"%s\" to a view" ,
406+ errmsg ("could not convert table \"%s\" to a view because it is not empty " ,
406407 event_obj -> relname )));
407408 heap_endscan (scanDesc );
408409
410+ if (event_relation -> rd_rel -> reltriggers != 0 )
411+ ereport (ERROR ,
412+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
413+ errmsg ("could not convert table \"%s\" to a view because it has triggers" ,
414+ event_obj -> relname ),
415+ errhint ("In particular, the table may not be involved in any foreign key relationships." )));
416+
417+ if (event_relation -> rd_rel -> relhasindex )
418+ ereport (ERROR ,
419+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
420+ errmsg ("could not convert table \"%s\" to a view because it has indexes" ,
421+ event_obj -> relname )));
422+
423+ if (event_relation -> rd_rel -> relhassubclass )
424+ ereport (ERROR ,
425+ (errcode (ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE ),
426+ errmsg ("could not convert table \"%s\" to a view because it has child tables" ,
427+ event_obj -> relname )));
428+
409429 RelisBecomingView = true;
410430 }
411431 }
@@ -456,6 +476,8 @@ DefineQueryRewrite(RuleStmt *stmt)
456476 * IF the relation is becoming a view, delete the storage files
457477 * associated with it. NB: we had better have AccessExclusiveLock to
458478 * do this ...
479+ *
480+ * XXX what about getting rid of its TOAST table? For now, we don't.
459481 */
460482 if (RelisBecomingView )
461483 smgrunlink (DEFAULT_SMGR , event_relation );
0 commit comments