summaryrefslogtreecommitdiff
path: root/src/backend/commands
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/commands')
-rw-r--r--src/backend/commands/command.c29
-rw-r--r--src/backend/commands/comment.c9
-rw-r--r--src/backend/commands/vacuum.c4
-rw-r--r--src/backend/commands/view.c4
4 files changed, 31 insertions, 15 deletions
diff --git a/src/backend/commands/command.c b/src/backend/commands/command.c
index d0de9e2e4d..d0faa943cf 100644
--- a/src/backend/commands/command.c
+++ b/src/backend/commands/command.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.100 2000/09/12 04:33:18 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/command.c,v 1.101 2000/09/12 04:49:06 momjian Exp $
*
* NOTES
* The PerformAddAttribute() code, like most of the relation
@@ -533,6 +533,9 @@ AlterTableAlterColumn(const char *relationName,
#endif
rel = heap_openr(relationName, AccessExclusiveLock);
+ if ( rel->rd_rel->relkind == RELKIND_VIEW )
+ elog(ERROR, "ALTER TABLE: %s is a view", relationName);
+
myrelid = RelationGetRelid(rel);
heap_close(rel, NoLock);
@@ -1133,6 +1136,10 @@ AlterTableAddConstraint(char *relationName,
rel = heap_openr(relationName, AccessExclusiveLock);
+ /* make sure it is not a view */
+ if (rel->rd_rel->relkind == RELKIND_VIEW)
+ elog(ERROR, "ALTER TABLE: cannot add constraint to a view");
+
/*
* Scan all of the rows, looking for a false match
*/
@@ -1251,19 +1258,20 @@ AlterTableAddConstraint(char *relationName,
elog(ERROR, "ALTER TABLE / ADD CONSTRAINT: Unable to reference temporary table from permanent table constraint.");
}
- /* check to see if the referenced table is a view. */
- if (is_viewr(fkconstraint->pktable_name))
- elog(ERROR, "ALTER TABLE: Cannot add constraints to views.");
-
/*
* Grab an exclusive lock on the pk table, so that someone
* doesn't delete rows out from under us.
*/
pkrel = heap_openr(fkconstraint->pktable_name, AccessExclusiveLock);
- if (pkrel == NULL)
- elog(ERROR, "referenced table \"%s\" not found",
+ if (pkrel == NULL)
+ elog(ERROR, "referenced table \"%s\" not found",
+ fkconstraint->pktable_name);
+
+ if (pkrel->rd_rel->relkind != RELKIND_RELATION)
+ elog(ERROR, "referenced table \"%s\" not a relation",
fkconstraint->pktable_name);
+
/*
* Grab an exclusive lock on the fk table, and then scan
@@ -1277,6 +1285,9 @@ AlterTableAddConstraint(char *relationName,
elog(ERROR, "table \"%s\" not found",
relationName);
+ if (rel->rd_rel->relkind != RELKIND_RELATION)
+ elog(ERROR, "referencing table \"%s\" not a relation", relationName);
+
/* First we check for limited correctness of the constraint */
rel_attrs = pkrel->rd_att->attrs;
@@ -1503,6 +1514,7 @@ AlterTableCreateToastTable(const char *relationName, bool silent)
* allow to create TOAST tables for views. But why not - someone
* can insert into a view, so it shouldn't be impossible to hide
* huge data there :-)
+ * Not any more.
*/
if (((Form_pg_class) GETSTRUCT(reltup))->relkind != RELKIND_RELATION)
{
@@ -1702,6 +1714,9 @@ LockTableCommand(LockStmt *lockstmt)
rel = heap_openr(lockstmt->relname, NoLock);
+ if (rel->rd_rel->relkind != RELKIND_RELATION)
+ elog(ERROR, "LOCK TABLE: %s is not a table", lockstmt->relname);
+
if (is_view(rel))
elog(ERROR, "LOCK TABLE: cannot lock a view");
diff --git a/src/backend/commands/comment.c b/src/backend/commands/comment.c
index 87c7d84727..51832bc2c7 100644
--- a/src/backend/commands/comment.c
+++ b/src/backend/commands/comment.c
@@ -21,6 +21,7 @@
#include "catalog/pg_shadow.h"
#include "catalog/pg_trigger.h"
#include "catalog/pg_type.h"
+#include "catalog/pg_class.h"
#include "commands/comment.h"
#include "miscadmin.h"
#include "parser/parse.h"
@@ -301,19 +302,19 @@ CommentRelation(int reltype, char *relname, char *comment)
switch (reltype)
{
case (INDEX):
- if (relkind != 'i')
+ if (relkind != RELKIND_INDEX)
elog(ERROR, "relation '%s' is not an index", relname);
break;
case (TABLE):
- if (relkind != 'r')
+ if (relkind != RELKIND_RELATION)
elog(ERROR, "relation '%s' is not a table", relname);
break;
case (VIEW):
- if (relkind != 'r')
+ if (relkind != RELKIND_VIEW)
elog(ERROR, "relation '%s' is not a view", relname);
break;
case (SEQUENCE):
- if (relkind != 'S')
+ if (relkind != RELKIND_SEQUENCE)
elog(ERROR, "relation '%s' is not a sequence", relname);
break;
}
diff --git a/src/backend/commands/vacuum.c b/src/backend/commands/vacuum.c
index 398d002ffc..7d4005d21d 100644
--- a/src/backend/commands/vacuum.c
+++ b/src/backend/commands/vacuum.c
@@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.164 2000/09/06 14:15:16 petere Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.165 2000/09/12 04:49:07 momjian Exp $
*
*-------------------------------------------------------------------------
@@ -306,7 +306,7 @@ getrels(NameData *VacRelP)
if (rkind != RELKIND_RELATION)
{
- elog(NOTICE, "Vacuum: can not process index and certain system tables");
+ elog(NOTICE, "Vacuum: can not process indecies, views and certain system tables");
continue;
}
diff --git a/src/backend/commands/view.c b/src/backend/commands/view.c
index 01e23d1315..af10805b71 100644
--- a/src/backend/commands/view.c
+++ b/src/backend/commands/view.c
@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: view.c,v 1.46 2000/09/12 04:15:56 momjian Exp $
+ * $Id: view.c,v 1.47 2000/09/12 04:49:07 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@@ -102,7 +102,7 @@ DefineVirtualRelation(char *relname, List *tlist)
/*
* finally create the relation...
*/
- DefineRelation(&createStmt, RELKIND_RELATION);
+ DefineRelation(&createStmt, RELKIND_VIEW);
}
/*------------------------------------------------------------------