Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b73da6

Browse files
committed
Disallow converting a table to a view if it has triggers, indexes, or
child tables --- all cases that will trip various sanity checks elsewherein the system, as well as cases that should not occur in the only intendeduse of this feature, namely coping with ancient pg_dump representationof views. Per bug report from Chris Pizzi.
1 parente8839c2 commit6b73da6

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

‎src/backend/rewrite/rewriteDefine.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
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("cannotconvertnon-emptytable \"%s\" to a view",
406+
errmsg("could notconvert 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

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp