1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* utility.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* Contains functions which control the execution of the POSTGRES utility
|
|
|
|
* commands. At one time acted as an interface between the Lisp and C
|
|
|
|
* systems.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-01-24 20:43:33 +01:00
|
|
|
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2001-10-12 02:07:15 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.120 2001/10/12 00:07:14 tgl Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include "postgres.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
|
1997-04-02 06:06:32 +02:00
|
|
|
#include "access/heapam.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "catalog/catalog.h"
|
2001-01-27 11:19:52 +01:00
|
|
|
#include "catalog/pg_shadow.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "commands/async.h"
|
|
|
|
#include "commands/cluster.h"
|
|
|
|
#include "commands/command.h"
|
1999-10-26 05:12:39 +02:00
|
|
|
#include "commands/comment.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "commands/copy.h"
|
|
|
|
#include "commands/creatinh.h"
|
1997-11-24 06:32:56 +01:00
|
|
|
#include "commands/dbcommands.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "commands/defrem.h"
|
|
|
|
#include "commands/explain.h"
|
1997-10-28 16:11:45 +01:00
|
|
|
#include "commands/proclang.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "commands/rename.h"
|
|
|
|
#include "commands/sequence.h"
|
|
|
|
#include "commands/trigger.h"
|
1999-12-20 02:19:58 +01:00
|
|
|
#include "commands/user.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "commands/vacuum.h"
|
1998-01-05 19:43:18 +01:00
|
|
|
#include "commands/variable.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "commands/view.h"
|
|
|
|
#include "miscadmin.h"
|
1999-12-20 02:19:58 +01:00
|
|
|
#include "parser/parse.h"
|
2001-01-05 07:34:23 +01:00
|
|
|
#include "parser/parse_clause.h"
|
2000-10-07 02:58:23 +02:00
|
|
|
#include "parser/parse_expr.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "rewrite/rewriteDefine.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "rewrite/rewriteRemove.h"
|
1996-11-11 05:54:54 +01:00
|
|
|
#include "tcop/utility.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "utils/acl.h"
|
1999-07-16 07:00:38 +02:00
|
|
|
#include "utils/ps_status.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
#include "utils/syscache.h"
|
2001-06-18 18:13:21 +02:00
|
|
|
#include "utils/temprel.h"
|
2000-11-05 23:50:21 +01:00
|
|
|
#include "access/xlog.h"
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-10-18 18:16:18 +02:00
|
|
|
/*
|
2000-10-23 01:32:48 +02:00
|
|
|
* Error-checking support for DROP commands
|
2000-10-18 18:16:18 +02:00
|
|
|
*/
|
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
struct kindstrings
|
|
|
|
{
|
|
|
|
char kind;
|
|
|
|
char *indef_article;
|
|
|
|
char *name;
|
|
|
|
char *command;
|
2000-10-18 18:16:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct kindstrings kindstringarray[] = {
|
2001-03-22 05:01:46 +01:00
|
|
|
{RELKIND_RELATION, "a", "table", "TABLE"},
|
|
|
|
{RELKIND_SEQUENCE, "a", "sequence", "SEQUENCE"},
|
|
|
|
{RELKIND_VIEW, "a", "view", "VIEW"},
|
|
|
|
{RELKIND_INDEX, "an", "index", "INDEX"},
|
|
|
|
{'\0', "a", "???", "???"}
|
2000-10-18 18:16:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-03-22 05:01:46 +01:00
|
|
|
DropErrorMsg(char *relname, char wrongkind, char rightkind)
|
2000-10-18 18:16:18 +02:00
|
|
|
{
|
|
|
|
struct kindstrings *rentry;
|
|
|
|
struct kindstrings *wentry;
|
|
|
|
|
|
|
|
for (rentry = kindstringarray; rentry->kind != '\0'; rentry++)
|
|
|
|
if (rentry->kind == rightkind)
|
|
|
|
break;
|
|
|
|
Assert(rentry->kind != '\0');
|
|
|
|
|
|
|
|
for (wentry = kindstringarray; wentry->kind != '\0'; wentry++)
|
|
|
|
if (wentry->kind == wrongkind)
|
|
|
|
break;
|
2000-11-07 03:17:50 +01:00
|
|
|
/* wrongkind could be something we don't have in our table... */
|
|
|
|
if (wentry->kind != '\0')
|
|
|
|
elog(ERROR, "\"%s\" is not %s %s. Use DROP %s to remove %s %s",
|
|
|
|
relname, rentry->indef_article, rentry->name,
|
|
|
|
wentry->command, wentry->indef_article, wentry->name);
|
|
|
|
else
|
|
|
|
elog(ERROR, "\"%s\" is not %s %s",
|
|
|
|
relname, rentry->indef_article, rentry->name);
|
2000-10-18 18:16:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2000-10-23 01:32:48 +02:00
|
|
|
CheckDropPermissions(char *name, char rightkind)
|
2000-10-18 18:16:18 +02:00
|
|
|
{
|
|
|
|
struct kindstrings *rentry;
|
2000-10-23 01:32:48 +02:00
|
|
|
HeapTuple tuple;
|
2000-10-18 18:16:18 +02:00
|
|
|
Form_pg_class classform;
|
|
|
|
|
2000-10-23 01:32:48 +02:00
|
|
|
for (rentry = kindstringarray; rentry->kind != '\0'; rentry++)
|
|
|
|
if (rentry->kind == rightkind)
|
|
|
|
break;
|
|
|
|
Assert(rentry->kind != '\0');
|
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
tuple = SearchSysCache(RELNAME,
|
|
|
|
PointerGetDatum(name),
|
|
|
|
0, 0, 0);
|
2000-10-18 18:16:18 +02:00
|
|
|
if (!HeapTupleIsValid(tuple))
|
2000-10-23 01:32:48 +02:00
|
|
|
elog(ERROR, "%s \"%s\" does not exist", rentry->name, name);
|
2000-10-18 18:16:18 +02:00
|
|
|
|
|
|
|
classform = (Form_pg_class) GETSTRUCT(tuple);
|
|
|
|
|
|
|
|
if (classform->relkind != rightkind)
|
|
|
|
DropErrorMsg(name, classform->relkind, rightkind);
|
2000-10-23 01:32:48 +02:00
|
|
|
|
|
|
|
if (!pg_ownercheck(GetUserId(), name, RELNAME))
|
|
|
|
elog(ERROR, "you do not own %s \"%s\"",
|
|
|
|
rentry->name, name);
|
|
|
|
|
2001-06-18 18:13:21 +02:00
|
|
|
if (!allowSystemTableMods && IsSystemRelationName(name) &&
|
|
|
|
!is_temp_relname(name))
|
2000-10-23 01:32:48 +02:00
|
|
|
elog(ERROR, "%s \"%s\" is a system %s",
|
|
|
|
rentry->name, name, rentry->name);
|
2000-11-16 23:30:52 +01:00
|
|
|
|
|
|
|
ReleaseSysCache(tuple);
|
2000-10-18 18:16:18 +02:00
|
|
|
}
|
|
|
|
|
2000-10-23 01:32:48 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* general utility function invoker
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
void
|
1998-02-26 05:46:47 +01:00
|
|
|
ProcessUtility(Node *parsetree,
|
1997-09-07 07:04:48 +02:00
|
|
|
CommandDest dest)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *commandTag = NULL;
|
|
|
|
char *relname;
|
|
|
|
char *relationName;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
switch (nodeTag(parsetree))
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* ******************************** transactions ********************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_TransactionStmt:
|
|
|
|
{
|
|
|
|
TransactionStmt *stmt = (TransactionStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
switch (stmt->command)
|
|
|
|
{
|
|
|
|
case BEGIN_TRANS:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "BEGIN");
|
1997-09-08 04:41:22 +02:00
|
|
|
BeginTransactionBlock();
|
|
|
|
break;
|
|
|
|
|
2000-01-29 17:58:54 +01:00
|
|
|
case COMMIT:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "COMMIT");
|
1997-09-08 04:41:22 +02:00
|
|
|
EndTransactionBlock();
|
|
|
|
break;
|
|
|
|
|
2000-01-29 17:58:54 +01:00
|
|
|
case ROLLBACK:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "ROLLBACK");
|
1997-09-08 04:41:22 +02:00
|
|
|
UserAbortTransactionBlock();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ******************************** portal manipulation ********************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_ClosePortalStmt:
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
ClosePortalStmt *stmt = (ClosePortalStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CLOSE");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
PerformPortalClose(stmt->portalname, dest);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_FetchStmt:
|
|
|
|
{
|
|
|
|
FetchStmt *stmt = (FetchStmt *) parsetree;
|
|
|
|
char *portalName = stmt->portalname;
|
|
|
|
bool forward;
|
|
|
|
int count;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = (stmt->ismove) ? "MOVE" : "FETCH");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-04-04 23:44:40 +02:00
|
|
|
SetQuerySnapshot();
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
forward = (bool) (stmt->direction == FORWARD);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* parser ensures that count is >= 0 and 'fetch ALL' -> 0
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
count = stmt->howMany;
|
1997-10-28 16:11:45 +01:00
|
|
|
PerformPortalFetch(portalName, forward, count, commandTag,
|
|
|
|
(stmt->ismove) ? None : dest); /* /dev/null for MOVE */
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-08 04:41:22 +02:00
|
|
|
* ******************************** relation and attribute
|
|
|
|
* manipulation ********************************
|
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_CreateStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-06 07:13:14 +02:00
|
|
|
DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION);
|
2000-07-05 14:45:31 +02:00
|
|
|
|
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* Let AlterTableCreateToastTable decide if this one needs a
|
|
|
|
* secondary relation too.
|
2000-07-05 14:45:31 +02:00
|
|
|
*/
|
|
|
|
CommandCounterIncrement();
|
2001-03-22 05:01:46 +01:00
|
|
|
AlterTableCreateToastTable(((CreateStmt *) parsetree)->relname,
|
|
|
|
true);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
1999-12-10 04:56:14 +01:00
|
|
|
case T_DropStmt:
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
2000-04-12 19:17:23 +02:00
|
|
|
DropStmt *stmt = (DropStmt *) parsetree;
|
2000-10-18 18:16:18 +02:00
|
|
|
List *args = stmt->names;
|
1999-09-18 21:08:25 +02:00
|
|
|
List *arg;
|
1997-09-08 04:41:22 +02:00
|
|
|
|
2000-10-23 01:32:48 +02:00
|
|
|
set_ps_display(commandTag = "DROP");
|
1999-09-18 21:08:25 +02:00
|
|
|
|
2000-10-23 01:32:48 +02:00
|
|
|
foreach(arg, args)
|
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
relname = strVal(lfirst(arg));
|
2000-10-18 18:16:18 +02:00
|
|
|
|
2001-03-22 05:01:46 +01:00
|
|
|
switch (stmt->removeType)
|
2000-10-18 18:16:18 +02:00
|
|
|
{
|
|
|
|
case DROP_TABLE:
|
2000-10-23 01:32:48 +02:00
|
|
|
CheckDropPermissions(relname, RELKIND_RELATION);
|
2000-10-18 18:16:18 +02:00
|
|
|
RemoveRelation(relname);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DROP_SEQUENCE:
|
2000-10-23 01:32:48 +02:00
|
|
|
CheckDropPermissions(relname, RELKIND_SEQUENCE);
|
2000-10-18 18:16:18 +02:00
|
|
|
RemoveRelation(relname);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DROP_VIEW:
|
2000-10-23 01:32:48 +02:00
|
|
|
CheckDropPermissions(relname, RELKIND_VIEW);
|
2000-10-18 18:16:18 +02:00
|
|
|
RemoveView(relname);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DROP_INDEX:
|
2000-10-23 01:32:48 +02:00
|
|
|
CheckDropPermissions(relname, RELKIND_INDEX);
|
2000-10-18 18:16:18 +02:00
|
|
|
RemoveIndex(relname);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DROP_RULE:
|
|
|
|
{
|
|
|
|
char *rulename = relname;
|
|
|
|
int aclcheck_result;
|
|
|
|
|
|
|
|
relationName = RewriteGetRuleEventRel(rulename);
|
2001-05-27 11:59:30 +02:00
|
|
|
aclcheck_result = pg_aclcheck(relationName, GetUserId(), ACL_RULE);
|
2000-10-18 18:16:18 +02:00
|
|
|
if (aclcheck_result != ACLCHECK_OK)
|
2001-03-22 05:01:46 +01:00
|
|
|
elog(ERROR, "%s: %s", relationName,
|
|
|
|
aclcheck_error_strings[aclcheck_result]);
|
2000-10-18 18:16:18 +02:00
|
|
|
RemoveRewriteRule(rulename);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case DROP_TYPE_P:
|
2000-10-23 01:32:48 +02:00
|
|
|
/* RemoveType does its own permissions checks */
|
2000-10-18 18:16:18 +02:00
|
|
|
RemoveType(relname);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2000-10-23 01:32:48 +02:00
|
|
|
/*
|
2001-03-22 05:01:46 +01:00
|
|
|
* Make sure subsequent loop iterations will see
|
|
|
|
* results of this one; needed if removing multiple
|
|
|
|
* rules for same table, for example.
|
2000-10-23 01:32:48 +02:00
|
|
|
*/
|
|
|
|
CommandCounterIncrement();
|
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
1999-09-30 03:12:36 +02:00
|
|
|
case T_TruncateStmt:
|
|
|
|
{
|
|
|
|
Relation rel;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "TRUNCATE");
|
1999-09-30 03:12:36 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
relname = ((TruncateStmt *) parsetree)->relName;
|
1999-09-30 03:12:36 +02:00
|
|
|
if (!allowSystemTableMods && IsSystemRelationName(relname))
|
|
|
|
elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table",
|
|
|
|
relname);
|
|
|
|
|
|
|
|
/* Grab exclusive lock in preparation for truncate... */
|
|
|
|
rel = heap_openr(relname, AccessExclusiveLock);
|
2000-04-12 19:17:23 +02:00
|
|
|
if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
|
1999-09-30 03:12:36 +02:00
|
|
|
elog(ERROR, "TRUNCATE cannot be used on sequences. '%s' is a sequence",
|
|
|
|
relname);
|
2000-09-12 06:49:17 +02:00
|
|
|
if (rel->rd_rel->relkind == RELKIND_VIEW)
|
2001-10-09 16:00:22 +02:00
|
|
|
elog(ERROR, "TRUNCATE cannot be used on views. '%s' is a view",
|
2000-09-12 06:49:17 +02:00
|
|
|
relname);
|
2000-04-12 19:17:23 +02:00
|
|
|
heap_close(rel, NoLock);
|
1999-09-30 03:12:36 +02:00
|
|
|
|
2000-09-06 16:15:31 +02:00
|
|
|
if (!pg_ownercheck(GetUserId(), relname, RELNAME))
|
1999-09-30 03:12:36 +02:00
|
|
|
elog(ERROR, "you do not own class \"%s\"", relname);
|
|
|
|
TruncateRelation(relname);
|
1999-09-23 19:03:39 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
case T_CommentStmt:
|
|
|
|
{
|
|
|
|
CommentStmt *statement;
|
|
|
|
|
|
|
|
statement = ((CommentStmt *) parsetree);
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "COMMENT");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
CommentObject(statement->objtype, statement->objname,
|
|
|
|
statement->objproperty, statement->objlist,
|
|
|
|
statement->comment);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_CopyStmt:
|
|
|
|
{
|
|
|
|
CopyStmt *stmt = (CopyStmt *) parsetree;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "COPY");
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-04-04 23:44:40 +02:00
|
|
|
if (stmt->direction != FROM)
|
|
|
|
SetQuerySnapshot();
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
DoCopy(stmt->relname,
|
|
|
|
stmt->binary,
|
|
|
|
stmt->oids,
|
|
|
|
(bool) (stmt->direction == FROM),
|
|
|
|
(bool) (stmt->filename == NULL),
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* null filename means copy to/from stdout/stdin, rather
|
|
|
|
* than to/from a file.
|
|
|
|
*/
|
|
|
|
stmt->filename,
|
1999-11-21 05:16:17 +01:00
|
|
|
stmt->delimiter,
|
2000-04-12 19:17:23 +02:00
|
|
|
stmt->null_print);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/*
|
1997-09-08 04:41:22 +02:00
|
|
|
* schema
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RenameStmt:
|
|
|
|
{
|
|
|
|
RenameStmt *stmt = (RenameStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "ALTER");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
relname = stmt->relname;
|
1999-03-17 23:53:31 +01:00
|
|
|
if (!allowSystemTableMods && IsSystemRelationName(relname))
|
2000-01-29 17:58:54 +01:00
|
|
|
elog(ERROR, "ALTER TABLE: relation \"%s\" is a system catalog",
|
1997-09-08 04:41:22 +02:00
|
|
|
relname);
|
2000-09-06 16:15:31 +02:00
|
|
|
if (!pg_ownercheck(GetUserId(), relname, RELNAME))
|
2000-01-29 17:58:54 +01:00
|
|
|
elog(ERROR, "permission denied");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-08 04:41:22 +02:00
|
|
|
* XXX using len == 3 to tell the difference
|
|
|
|
* between "rename rel to newrel" and
|
|
|
|
* "rename att in rel to newatt" will not
|
|
|
|
* work soon because "rename type/operator/rule"
|
|
|
|
* stuff is being added. - cim 10/24/90
|
1997-09-07 07:04:48 +02:00
|
|
|
* ----------------
|
1997-09-08 04:41:22 +02:00
|
|
|
* [another piece of amuzing but useless anecdote -- ay]
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1997-09-08 04:41:22 +02:00
|
|
|
if (stmt->column == NULL)
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rename relation
|
1997-09-08 04:41:22 +02:00
|
|
|
*
|
2001-03-22 07:16:21 +01:00
|
|
|
* Note: we also rename the "type" tuple corresponding to
|
|
|
|
* the relation.
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
renamerel(relname, /* old name */
|
|
|
|
stmt->newname); /* new name */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2001-03-22 07:16:21 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* rename attribute
|
1997-09-08 04:41:22 +02:00
|
|
|
*/
|
|
|
|
renameatt(relname, /* relname */
|
|
|
|
stmt->column, /* old att name */
|
|
|
|
stmt->newname, /* new att name */
|
2001-03-22 05:01:46 +01:00
|
|
|
interpretInhOption(stmt->inhOpt)); /* recursive? */
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
/* various Alter Table forms */
|
2000-01-16 21:05:00 +01:00
|
|
|
|
|
|
|
case T_AlterTableStmt:
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
|
|
|
AlterTableStmt *stmt = (AlterTableStmt *) parsetree;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "ALTER");
|
2000-04-12 19:17:23 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some or all of these functions are recursive to cover
|
|
|
|
* inherited things, so permission checks are done there.
|
|
|
|
*/
|
|
|
|
switch (stmt->subtype)
|
|
|
|
{
|
|
|
|
case 'A': /* ADD COLUMN */
|
2001-01-05 07:34:23 +01:00
|
|
|
AlterTableAddColumn(stmt->relname,
|
2001-03-22 05:01:46 +01:00
|
|
|
interpretInhOption(stmt->inhOpt),
|
2001-01-05 07:34:23 +01:00
|
|
|
(ColumnDef *) stmt->def);
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
2001-05-07 02:43:27 +02:00
|
|
|
case 'T': /* ALTER COLUMN DEFAULT */
|
|
|
|
AlterTableAlterColumnDefault(stmt->relname,
|
2001-03-22 05:01:46 +01:00
|
|
|
interpretInhOption(stmt->inhOpt),
|
2001-05-07 02:43:27 +02:00
|
|
|
stmt->name,
|
|
|
|
stmt->def);
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
2001-05-07 02:43:27 +02:00
|
|
|
case 'S': /* ALTER COLUMN STATISTICS */
|
|
|
|
AlterTableAlterColumnStatistics(stmt->relname,
|
|
|
|
interpretInhOption(stmt->inhOpt),
|
|
|
|
stmt->name,
|
|
|
|
stmt->def);
|
|
|
|
break;
|
|
|
|
case 'D': /* DROP COLUMN */
|
2001-01-05 07:34:23 +01:00
|
|
|
AlterTableDropColumn(stmt->relname,
|
2001-03-22 05:01:46 +01:00
|
|
|
interpretInhOption(stmt->inhOpt),
|
2001-01-05 07:34:23 +01:00
|
|
|
stmt->name,
|
|
|
|
stmt->behavior);
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
|
|
|
case 'C': /* ADD CONSTRAINT */
|
2001-01-05 07:34:23 +01:00
|
|
|
AlterTableAddConstraint(stmt->relname,
|
2001-03-22 05:01:46 +01:00
|
|
|
interpretInhOption(stmt->inhOpt),
|
2001-10-12 02:07:15 +02:00
|
|
|
(List *) stmt->def);
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
|
|
|
case 'X': /* DROP CONSTRAINT */
|
2001-01-05 07:34:23 +01:00
|
|
|
AlterTableDropConstraint(stmt->relname,
|
2001-03-22 05:01:46 +01:00
|
|
|
interpretInhOption(stmt->inhOpt),
|
2001-01-05 07:34:23 +01:00
|
|
|
stmt->name,
|
|
|
|
stmt->behavior);
|
2000-04-12 19:17:23 +02:00
|
|
|
break;
|
2000-07-04 01:10:14 +02:00
|
|
|
case 'E': /* CREATE TOAST TABLE */
|
2001-01-05 07:34:23 +01:00
|
|
|
AlterTableCreateToastTable(stmt->relname,
|
|
|
|
false);
|
2000-07-04 01:10:14 +02:00
|
|
|
break;
|
2000-09-12 07:09:57 +02:00
|
|
|
case 'U': /* ALTER OWNER */
|
2001-01-05 07:34:23 +01:00
|
|
|
AlterTableOwner(stmt->relname,
|
|
|
|
stmt->name);
|
2000-09-12 07:09:57 +02:00
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
default: /* oops */
|
|
|
|
elog(ERROR, "T_AlterTableStmt: unknown subtype");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-01-16 21:05:00 +01:00
|
|
|
|
|
|
|
|
2001-06-10 01:21:55 +02:00
|
|
|
case T_GrantStmt:
|
1997-09-08 04:41:22 +02:00
|
|
|
{
|
2001-06-10 01:21:55 +02:00
|
|
|
GrantStmt *stmt = (GrantStmt *) parsetree;
|
|
|
|
commandTag = stmt->is_grant ? "GRANT" : "REVOKE";
|
|
|
|
set_ps_display(commandTag);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-06-10 01:21:55 +02:00
|
|
|
ExecuteGrantStmt(stmt);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* ******************************** object creation /
|
|
|
|
* destruction ********************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_DefineStmt:
|
|
|
|
{
|
|
|
|
DefineStmt *stmt = (DefineStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
switch (stmt->defType)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
case OPERATOR:
|
|
|
|
DefineOperator(stmt->defname, /* operator name */
|
|
|
|
stmt->definition); /* rest */
|
|
|
|
break;
|
1997-10-25 07:34:07 +02:00
|
|
|
case TYPE_P:
|
1998-09-01 06:40:42 +02:00
|
|
|
DefineType(stmt->defname, stmt->definition);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
case AGGREGATE:
|
|
|
|
DefineAggregate(stmt->defname, /* aggregate name */
|
|
|
|
stmt->definition); /* rest */
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
}
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_ViewStmt: /* CREATE VIEW */
|
|
|
|
{
|
|
|
|
ViewStmt *stmt = (ViewStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
DefineView(stmt->viewname, stmt->query); /* retrieve parsetree */
|
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_ProcedureStmt: /* CREATE FUNCTION */
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
2001-09-08 03:10:21 +02:00
|
|
|
CreateFunction((ProcedureStmt *) parsetree);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_IndexStmt: /* CREATE INDEX */
|
|
|
|
{
|
|
|
|
IndexStmt *stmt = (IndexStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
DefineIndex(stmt->relname, /* relation name */
|
|
|
|
stmt->idxname, /* index name */
|
|
|
|
stmt->accessMethod, /* am name */
|
|
|
|
stmt->indexParams, /* parameters */
|
|
|
|
stmt->unique,
|
1999-01-26 15:38:52 +01:00
|
|
|
stmt->primary,
|
1997-09-08 04:41:22 +02:00
|
|
|
(Expr *) stmt->whereClause,
|
|
|
|
stmt->rangetable);
|
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RuleStmt: /* CREATE RULE */
|
|
|
|
{
|
|
|
|
RuleStmt *stmt = (RuleStmt *) parsetree;
|
|
|
|
int aclcheck_result;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
relname = stmt->object->relname;
|
2001-05-27 11:59:30 +02:00
|
|
|
aclcheck_result = pg_aclcheck(relname, GetUserId(), ACL_RULE);
|
1997-09-08 04:41:22 +02:00
|
|
|
if (aclcheck_result != ACLCHECK_OK)
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[aclcheck_result]);
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
DefineQueryRewrite(stmt);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_CreateSeqStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
DefineSequence((CreateSeqStmt *) parsetree);
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RemoveAggrStmt:
|
|
|
|
{
|
|
|
|
RemoveAggrStmt *stmt = (RemoveAggrStmt *) parsetree;
|
2000-10-07 02:58:23 +02:00
|
|
|
char *typename = (char *) NULL;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
|
|
|
if (stmt->aggtype != NULL)
|
|
|
|
typename = TypeNameToInternalName((TypeName *) stmt->aggtype);
|
|
|
|
|
|
|
|
RemoveAggregate(stmt->aggname, typename);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RemoveFuncStmt:
|
|
|
|
{
|
|
|
|
RemoveFuncStmt *stmt = (RemoveFuncStmt *) parsetree;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
|
|
|
RemoveFunction(stmt->funcname, stmt->args);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RemoveOperStmt:
|
|
|
|
{
|
|
|
|
RemoveOperStmt *stmt = (RemoveOperStmt *) parsetree;
|
2000-10-07 02:58:23 +02:00
|
|
|
TypeName *typenode1 = (TypeName *) lfirst(stmt->args);
|
|
|
|
TypeName *typenode2 = (TypeName *) lsecond(stmt->args);
|
|
|
|
char *typename1 = (char *) NULL;
|
|
|
|
char *typename2 = (char *) NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP");
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-10-07 02:58:23 +02:00
|
|
|
if (typenode1 != NULL)
|
|
|
|
typename1 = TypeNameToInternalName(typenode1);
|
|
|
|
if (typenode2 != NULL)
|
|
|
|
typename2 = TypeNameToInternalName(typenode2);
|
|
|
|
|
|
|
|
RemoveOperator(stmt->opname, typename1, typename2);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_VersionStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
elog(ERROR, "CREATE VERSION is not currently implemented");
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_CreatedbStmt:
|
|
|
|
{
|
|
|
|
CreatedbStmt *stmt = (CreatedbStmt *) parsetree;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE DATABASE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
2000-11-14 19:37:49 +01:00
|
|
|
createdb(stmt->dbname, stmt->dbpath,
|
|
|
|
stmt->dbtemplate, stmt->encoding);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-12-10 04:56:14 +01:00
|
|
|
case T_DropdbStmt:
|
1997-09-08 04:41:22 +02:00
|
|
|
{
|
1999-12-10 04:56:14 +01:00
|
|
|
DropdbStmt *stmt = (DropdbStmt *) parsetree;
|
1997-04-02 20:24:52 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP DATABASE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
2000-01-13 19:26:18 +01:00
|
|
|
dropdb(stmt->dbname);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/* Query-level asynchronous notification */
|
|
|
|
case T_NotifyStmt:
|
|
|
|
{
|
|
|
|
NotifyStmt *stmt = (NotifyStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "NOTIFY");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
Async_Notify(stmt->relname);
|
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_ListenStmt:
|
|
|
|
{
|
|
|
|
ListenStmt *stmt = (ListenStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "LISTEN");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-01-25 06:15:15 +01:00
|
|
|
Async_Listen(stmt->relname, MyProcPid);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-25 23:37:08 +02:00
|
|
|
case T_UnlistenStmt:
|
|
|
|
{
|
|
|
|
UnlistenStmt *stmt = (UnlistenStmt *) parsetree;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "UNLISTEN");
|
1998-08-25 23:37:08 +02:00
|
|
|
|
|
|
|
Async_Unlisten(stmt->relname, MyProcPid);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* ******************************** dynamic loader ********************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_LoadStmt:
|
|
|
|
{
|
|
|
|
LoadStmt *stmt = (LoadStmt *) parsetree;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "LOAD");
|
1997-09-08 04:41:22 +02:00
|
|
|
|
1999-05-25 18:15:34 +02:00
|
|
|
closeAllVfds(); /* probably not necessary... */
|
1999-05-22 21:49:42 +02:00
|
|
|
load_file(stmt->filename);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_ClusterStmt:
|
|
|
|
{
|
|
|
|
ClusterStmt *stmt = (ClusterStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CLUSTER");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-08 17:31:06 +01:00
|
|
|
relname = stmt->relname;
|
|
|
|
if (IsSystemRelationName(relname))
|
|
|
|
elog(ERROR, "CLUSTER: relation \"%s\" is a system catalog",
|
|
|
|
relname);
|
|
|
|
if (!pg_ownercheck(GetUserId(), relname, RELNAME))
|
|
|
|
elog(ERROR, "permission denied");
|
|
|
|
|
|
|
|
cluster(relname, stmt->indexname);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VacuumStmt:
|
2001-05-07 02:43:27 +02:00
|
|
|
if (((VacuumStmt *) parsetree)->vacuum)
|
|
|
|
commandTag = "VACUUM";
|
|
|
|
else
|
|
|
|
commandTag = "ANALYZE";
|
|
|
|
set_ps_display(commandTag);
|
2000-10-07 02:58:23 +02:00
|
|
|
|
2001-05-07 02:43:27 +02:00
|
|
|
vacuum((VacuumStmt *) parsetree);
|
1997-09-08 04:41:22 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case T_ExplainStmt:
|
|
|
|
{
|
|
|
|
ExplainStmt *stmt = (ExplainStmt *) parsetree;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "EXPLAIN");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-09-18 03:59:07 +02:00
|
|
|
ExplainQuery(stmt->query, stmt->verbose, stmt->analyze, dest);
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-24 18:29:06 +01:00
|
|
|
#ifdef NOT_USED
|
1999-05-25 18:15:34 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* ******************************** Tioga-related statements *******************************
|
|
|
|
*/
|
|
|
|
case T_RecipeStmt:
|
|
|
|
{
|
|
|
|
RecipeStmt *stmt = (RecipeStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "EXECUTE RECIPE");
|
2000-10-07 02:58:23 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
beginRecipe(stmt);
|
|
|
|
}
|
|
|
|
break;
|
1999-02-24 18:29:06 +01:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* ******************************** set variable statements *******************************
|
|
|
|
*/
|
|
|
|
case T_VariableSetStmt:
|
|
|
|
{
|
|
|
|
VariableSetStmt *n = (VariableSetStmt *) parsetree;
|
|
|
|
|
|
|
|
SetPGVariable(n->name, n->value);
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "SET VARIABLE");
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VariableShowStmt:
|
|
|
|
{
|
|
|
|
VariableShowStmt *n = (VariableShowStmt *) parsetree;
|
|
|
|
|
|
|
|
GetPGVariable(n->name);
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "SHOW VARIABLE");
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VariableResetStmt:
|
|
|
|
{
|
|
|
|
VariableResetStmt *n = (VariableResetStmt *) parsetree;
|
|
|
|
|
|
|
|
ResetPGVariable(n->name);
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "RESET VARIABLE");
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ******************************** TRIGGER statements *******************************
|
|
|
|
*/
|
|
|
|
case T_CreateTrigStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
1997-09-08 04:41:22 +02:00
|
|
|
|
|
|
|
CreateTrigger((CreateTrigStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DropTrigStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP");
|
1997-09-08 04:41:22 +02:00
|
|
|
|
|
|
|
DropTrigger((DropTrigStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
1997-10-28 16:11:45 +01:00
|
|
|
/*
|
|
|
|
* ************* PROCEDURAL LANGUAGE statements *****************
|
|
|
|
*/
|
|
|
|
case T_CreatePLangStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE");
|
1997-10-28 16:11:45 +01:00
|
|
|
|
|
|
|
CreateProceduralLanguage((CreatePLangStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DropPLangStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP");
|
1997-10-28 16:11:45 +01:00
|
|
|
|
|
|
|
DropProceduralLanguage((DropPLangStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
/*
|
|
|
|
* ******************************** USER statements ****
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_CreateUserStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE USER");
|
1997-12-04 01:28:15 +01:00
|
|
|
|
2000-01-14 23:11:38 +01:00
|
|
|
CreateUser((CreateUserStmt *) parsetree);
|
1998-02-26 05:46:47 +01:00
|
|
|
break;
|
1997-12-04 01:28:15 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
case T_AlterUserStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "ALTER USER");
|
1997-12-04 01:28:15 +01:00
|
|
|
|
2000-01-14 23:11:38 +01:00
|
|
|
AlterUser((AlterUserStmt *) parsetree);
|
1998-02-26 05:46:47 +01:00
|
|
|
break;
|
1997-12-04 01:28:15 +01:00
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
case T_DropUserStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP USER");
|
1997-12-04 01:28:15 +01:00
|
|
|
|
2000-01-14 23:11:38 +01:00
|
|
|
DropUser((DropUserStmt *) parsetree);
|
1998-02-26 05:46:47 +01:00
|
|
|
break;
|
1997-12-04 01:28:15 +01:00
|
|
|
|
1998-12-18 10:10:39 +01:00
|
|
|
case T_LockStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "LOCK TABLE");
|
1998-12-18 10:10:39 +01:00
|
|
|
|
|
|
|
LockTableCommand((LockStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
1999-09-29 18:06:40 +02:00
|
|
|
case T_ConstraintsSetStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "SET CONSTRAINTS");
|
1999-09-29 18:06:40 +02:00
|
|
|
|
|
|
|
DeferredTriggerSetState((ConstraintsSetStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
case T_CreateGroupStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "CREATE GROUP");
|
1999-12-16 18:24:19 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
CreateGroup((CreateGroupStmt *) parsetree);
|
|
|
|
break;
|
1999-12-16 18:24:19 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
case T_AlterGroupStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "ALTER GROUP");
|
1999-12-16 18:24:19 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
AlterGroup((AlterGroupStmt *) parsetree, "ALTER GROUP");
|
|
|
|
break;
|
1999-12-16 18:24:19 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
case T_DropGroupStmt:
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "DROP GROUP");
|
1999-12-16 18:24:19 +01:00
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
DropGroup((DropGroupStmt *) parsetree);
|
|
|
|
break;
|
1997-12-04 01:28:15 +01:00
|
|
|
|
2000-11-05 23:50:21 +01:00
|
|
|
case T_CheckPointStmt:
|
|
|
|
{
|
|
|
|
set_ps_display(commandTag = "CHECKPOINT");
|
|
|
|
|
2001-01-27 11:19:52 +01:00
|
|
|
if (!superuser())
|
|
|
|
elog(ERROR, "permission denied");
|
2000-11-05 23:50:21 +01:00
|
|
|
CreateCheckPoint(false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2000-02-18 10:30:20 +01:00
|
|
|
case T_ReindexStmt:
|
|
|
|
{
|
|
|
|
ReindexStmt *stmt = (ReindexStmt *) parsetree;
|
|
|
|
|
2000-06-04 03:44:38 +02:00
|
|
|
set_ps_display(commandTag = "REINDEX");
|
2000-02-18 10:30:20 +01:00
|
|
|
|
|
|
|
switch (stmt->reindexType)
|
|
|
|
{
|
|
|
|
case INDEX:
|
2000-04-12 19:17:23 +02:00
|
|
|
relname = (char *) stmt->name;
|
2000-02-18 10:30:20 +01:00
|
|
|
if (IsSystemRelationName(relname))
|
|
|
|
{
|
|
|
|
if (!allowSystemTableMods && IsSystemRelationName(relname))
|
2000-04-25 12:38:38 +02:00
|
|
|
elog(ERROR, "\"%s\" is a system index. call REINDEX under standalone postgres with -O -P options",
|
2001-03-22 05:01:46 +01:00
|
|
|
relname);
|
2000-02-18 10:30:20 +01:00
|
|
|
if (!IsIgnoringSystemIndexes())
|
2000-04-25 12:38:38 +02:00
|
|
|
elog(ERROR, "\"%s\" is a system index. call REINDEX under standalone postgres with -P -O options",
|
2001-03-22 05:01:46 +01:00
|
|
|
relname);
|
2000-02-18 10:30:20 +01:00
|
|
|
}
|
2000-09-06 16:15:31 +02:00
|
|
|
if (!pg_ownercheck(GetUserId(), relname, RELNAME))
|
2000-02-18 10:30:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
|
|
|
ReindexIndex(relname, stmt->force);
|
|
|
|
break;
|
|
|
|
case TABLE:
|
2000-04-12 19:17:23 +02:00
|
|
|
relname = (char *) stmt->name;
|
2000-09-06 16:15:31 +02:00
|
|
|
if (!pg_ownercheck(GetUserId(), relname, RELNAME))
|
2000-02-18 10:30:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
|
|
|
ReindexTable(relname, stmt->force);
|
|
|
|
break;
|
|
|
|
case DATABASE:
|
2000-04-12 19:17:23 +02:00
|
|
|
relname = (char *) stmt->name;
|
2000-02-18 10:30:20 +01:00
|
|
|
if (!allowSystemTableMods)
|
2000-04-25 12:38:38 +02:00
|
|
|
elog(ERROR, "must be called under standalone postgres with -O -P options");
|
2000-02-18 10:30:20 +01:00
|
|
|
if (!IsIgnoringSystemIndexes())
|
2000-04-25 12:38:38 +02:00
|
|
|
elog(ERROR, "must be called under standalone postgres with -P -O options");
|
2000-02-18 10:30:20 +01:00
|
|
|
ReindexDatabase(relname, stmt->force, false);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
2000-04-12 19:17:23 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* ******************************** default ********************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
default:
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "ProcessUtility: command #%d unsupported",
|
1997-09-08 04:41:22 +02:00
|
|
|
nodeTag(parsetree));
|
|
|
|
break;
|
1997-04-02 20:24:52 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* tell fe/be or whatever that we're done.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
EndCommand(commandTag, dest);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|