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
|
|
|
*
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1996-2000, PostgreSQL, Inc
|
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2000-04-12 19:17:23 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.86 2000/04/12 17:15:43 momjian 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"
|
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#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"
|
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"
|
1999-07-16 07:00:38 +02:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
/* ----------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* CHECK_IF_ABORTED() is used to avoid doing unnecessary
|
|
|
|
* processing within an aborted transaction block.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------
|
|
|
|
*/
|
1998-06-15 20:40:05 +02:00
|
|
|
/* we have to use IF because of the 'break' */
|
1996-07-09 08:22:35 +02:00
|
|
|
#define CHECK_IF_ABORTED() \
|
1998-06-15 20:40:05 +02:00
|
|
|
if (1) \
|
|
|
|
{ \
|
|
|
|
if (IsAbortedTransactionBlockState()) \
|
|
|
|
{ \
|
2000-01-29 17:58:54 +01:00
|
|
|
elog(NOTICE, "current transaction is aborted, " \
|
|
|
|
"queries ignored until end of transaction block"); \
|
1997-09-07 07:04:48 +02:00
|
|
|
commandTag = "*ABORT STATE*"; \
|
|
|
|
break; \
|
|
|
|
} \
|
1998-06-15 20:40:05 +02:00
|
|
|
} else
|
1997-09-07 07:04: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;
|
|
|
|
char *userName;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
userName = GetPgUserName();
|
|
|
|
|
|
|
|
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:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "BEGIN");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
BeginTransactionBlock();
|
|
|
|
break;
|
|
|
|
|
2000-01-29 17:58:54 +01:00
|
|
|
case COMMIT:
|
|
|
|
PS_SET_STATUS(commandTag = "COMMIT");
|
1997-09-08 04:41:22 +02:00
|
|
|
EndTransactionBlock();
|
|
|
|
break;
|
|
|
|
|
2000-01-29 17:58:54 +01:00
|
|
|
case ROLLBACK:
|
|
|
|
PS_SET_STATUS(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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CLOSE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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;
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = (stmt->ismove) ? "MOVE" : "FETCH");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-07 07:04:48 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
1998-08-06 07:13:14 +02:00
|
|
|
DefineRelation((CreateStmt *) parsetree, RELKIND_RELATION);
|
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;
|
1997-09-08 04:41:22 +02:00
|
|
|
List *args = stmt->relNames;
|
1999-09-18 21:08:25 +02:00
|
|
|
List *arg;
|
1997-09-08 04:41:22 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
/* check as much as we can before we start dropping ... */
|
1997-09-08 04:41:22 +02:00
|
|
|
foreach(arg, args)
|
1997-09-07 07:04:48 +02:00
|
|
|
{
|
1999-09-18 21:08:25 +02:00
|
|
|
Relation rel;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
relname = strVal(lfirst(arg));
|
1999-03-17 23:53:31 +01:00
|
|
|
if (!allowSystemTableMods && IsSystemRelationName(relname))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "class \"%s\" is a system catalog",
|
1997-09-07 07:04:48 +02:00
|
|
|
relname);
|
1999-09-18 21:08:25 +02:00
|
|
|
rel = heap_openr(relname, AccessExclusiveLock);
|
|
|
|
if (stmt->sequence &&
|
|
|
|
rel->rd_rel->relkind != RELKIND_SEQUENCE)
|
|
|
|
elog(ERROR, "Use DROP TABLE to drop table '%s'",
|
|
|
|
relname);
|
|
|
|
if (!(stmt->sequence) &&
|
|
|
|
rel->rd_rel->relkind == RELKIND_SEQUENCE)
|
|
|
|
elog(ERROR, "Use DROP SEQUENCE to drop sequence '%s'",
|
|
|
|
relname);
|
|
|
|
/* close rel, but keep lock until end of xact */
|
|
|
|
heap_close(rel, NoLock);
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifndef NO_SECURITY
|
1997-09-08 04:41:22 +02:00
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "you do not own class \"%s\"",
|
1997-09-08 04:41:22 +02:00
|
|
|
relname);
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
1999-09-18 21:08:25 +02:00
|
|
|
/* OK, terminate 'em all */
|
1997-09-08 04:41:22 +02:00
|
|
|
foreach(arg, args)
|
|
|
|
{
|
|
|
|
relname = strVal(lfirst(arg));
|
|
|
|
RemoveRelation(relname);
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
PS_SET_STATUS(commandTag = "TRUNCATE");
|
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
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-04-12 19:17:23 +02:00
|
|
|
heap_close(rel, NoLock);
|
1999-09-30 03:12:36 +02:00
|
|
|
|
1999-09-23 19:03:39 +02:00
|
|
|
#ifndef NO_SECURITY
|
1999-09-30 03:12:36 +02:00
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
|
|
|
elog(ERROR, "you do not own class \"%s\"", relname);
|
1999-09-23 19:03:39 +02:00
|
|
|
#endif
|
1999-09-30 03:12:36 +02:00
|
|
|
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);
|
|
|
|
|
|
|
|
PS_SET_STATUS(commandTag = "COMMENT");
|
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
CommentObject(statement->objtype, statement->objname,
|
|
|
|
statement->objproperty, statement->objlist,
|
|
|
|
statement->comment);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
This patch implements ORACLE's COMMENT SQL command.
>From the ORACLE 7 SQL Language Reference Manual:
-----------------------------------------------------
COMMENT
Purpose:
To add a comment about a table, view, snapshot, or
column into the data dictionary.
Prerequisites:
The table, view, or snapshot must be in your own
schema
or you must have COMMENT ANY TABLE system privilege.
Syntax:
COMMENT ON [ TABLE table ] |
[ COLUMN table.column] IS 'text'
You can effectively drop a comment from the database
by setting it to the empty string ''.
-----------------------------------------------------
Example:
COMMENT ON TABLE workorders IS
'Maintains base records for workorder information';
COMMENT ON COLUMN workorders.hours IS
'Number of hours the engineer worked on the task';
to drop a comment:
COMMENT ON COLUMN workorders.hours IS '';
The current patch will simply perform the insert into
pg_description, as per the TODO. And, of course, when
the table is dropped, any comments relating to it
or any of its attributes are also dropped. I haven't
looked at the ODBC source yet, but I do know from
an ODBC client standpoint that the standard does
support the notion of table and column comments.
Hopefully the ODBC driver is already fetching these
values from pg_description, but if not, it should be
trivial.
Hope this makes the grade,
Mike Mascari
(mascarim@yahoo.com)
1999-10-15 03:49:49 +02:00
|
|
|
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_CopyStmt:
|
|
|
|
{
|
|
|
|
CopyStmt *stmt = (CopyStmt *) parsetree;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "COPY");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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-01-29 17:58:54 +01:00
|
|
|
PS_SET_STATUS(commandTag = "ALTER");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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);
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifndef NO_SECURITY
|
1997-09-08 04:41:22 +02:00
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
2000-01-29 17:58:54 +01:00
|
|
|
elog(ERROR, "permission denied");
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
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)
|
|
|
|
{
|
|
|
|
/* ----------------
|
|
|
|
* rename relation
|
|
|
|
*
|
|
|
|
* Note: we also rename the "type" tuple
|
|
|
|
* corresponding to the relation.
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
renamerel(relname, /* old name */
|
|
|
|
stmt->newname); /* new name */
|
|
|
|
TypeRename(relname, /* old name */
|
|
|
|
stmt->newname); /* new name */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* ----------------
|
|
|
|
* rename attribute
|
|
|
|
* ----------------
|
|
|
|
*/
|
|
|
|
renameatt(relname, /* relname */
|
|
|
|
stmt->column, /* old att name */
|
|
|
|
stmt->newname, /* new att name */
|
|
|
|
userName,
|
|
|
|
stmt->inh); /* recursive? */
|
|
|
|
}
|
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;
|
|
|
|
|
|
|
|
PS_SET_STATUS(commandTag = "ALTER");
|
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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 */
|
|
|
|
AlterTableAddColumn(stmt->relname, stmt->inh, (ColumnDef *) stmt->def);
|
|
|
|
break;
|
|
|
|
case 'T': /* ALTER COLUMN */
|
|
|
|
AlterTableAlterColumn(stmt->relname, stmt->inh, stmt->name, stmt->def);
|
|
|
|
break;
|
|
|
|
case 'D': /* ALTER DROP */
|
|
|
|
AlterTableDropColumn(stmt->relname, stmt->inh, stmt->name, stmt->behavior);
|
|
|
|
break;
|
|
|
|
case 'C': /* ADD CONSTRAINT */
|
|
|
|
AlterTableAddConstraint(stmt->relname, stmt->inh, stmt->def);
|
|
|
|
break;
|
|
|
|
case 'X': /* DROP CONSTRAINT */
|
|
|
|
AlterTableDropConstraint(stmt->relname, stmt->inh, stmt->name, stmt->behavior);
|
|
|
|
break;
|
|
|
|
default: /* oops */
|
|
|
|
elog(ERROR, "T_AlterTableStmt: unknown subtype");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2000-01-16 21:05:00 +01:00
|
|
|
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_ChangeACLStmt:
|
|
|
|
{
|
|
|
|
ChangeACLStmt *stmt = (ChangeACLStmt *) parsetree;
|
|
|
|
List *i;
|
|
|
|
AclItem *aip;
|
|
|
|
unsigned modechg;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CHANGE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
aip = stmt->aclitem;
|
1997-09-08 23:56:23 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
modechg = stmt->modechg;
|
|
|
|
foreach(i, stmt->relNames)
|
2000-04-12 19:17:23 +02:00
|
|
|
{
|
2000-01-15 19:30:35 +01:00
|
|
|
Relation rel;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
relname = strVal(lfirst(i));
|
2000-01-15 19:30:35 +01:00
|
|
|
rel = heap_openr(relname, AccessExclusiveLock);
|
|
|
|
if (rel && rel->rd_rel->relkind == RELKIND_INDEX)
|
|
|
|
elog(ERROR, "\"%s\" is an index relation",
|
|
|
|
relname);
|
|
|
|
/* close rel, but keep lock until end of xact */
|
|
|
|
heap_close(rel, NoLock);
|
|
|
|
#ifndef NO_SECURITY
|
1997-09-08 04:41:22 +02:00
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "you do not own class \"%s\"",
|
1997-09-08 04:41:22 +02:00
|
|
|
relname);
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
ChangeAcl(relname, aip, modechg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
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 */
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-07 07:04:48 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-08 04:41:22 +02:00
|
|
|
CreateFunction((ProcedureStmt *) parsetree, dest); /* everything */
|
|
|
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
DefineIndex(stmt->relname, /* relation name */
|
|
|
|
stmt->idxname, /* index name */
|
|
|
|
stmt->accessMethod, /* am name */
|
|
|
|
stmt->indexParams, /* parameters */
|
|
|
|
stmt->withClause,
|
|
|
|
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
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
#ifndef NO_SECURITY
|
1997-09-08 04:41:22 +02:00
|
|
|
relname = stmt->object->relname;
|
|
|
|
aclcheck_result = pg_aclcheck(relname, userName, ACL_RU);
|
|
|
|
if (aclcheck_result != ACLCHECK_OK)
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[aclcheck_result]);
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
DefineQueryRewrite(stmt);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_CreateSeqStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-07 07:04:48 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
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_ExtendStmt:
|
|
|
|
{
|
|
|
|
ExtendStmt *stmt = (ExtendStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "EXTEND");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
ExtendIndex(stmt->idxname, /* index name */
|
|
|
|
(Expr *) stmt->whereClause, /* where */
|
|
|
|
stmt->rangetable);
|
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RemoveStmt:
|
|
|
|
{
|
|
|
|
RemoveStmt *stmt = (RemoveStmt *) parsetree;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
switch (stmt->removeType)
|
|
|
|
{
|
|
|
|
case INDEX:
|
|
|
|
relname = stmt->name;
|
1999-03-17 23:53:31 +01:00
|
|
|
if (!allowSystemTableMods && IsSystemRelationName(relname))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "class \"%s\" is a system catalog index",
|
1997-09-08 04:41:22 +02:00
|
|
|
relname);
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef NO_SECURITY
|
1997-09-08 04:41:22 +02:00
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
RemoveIndex(relname);
|
|
|
|
break;
|
|
|
|
case RULE:
|
|
|
|
{
|
|
|
|
char *rulename = stmt->name;
|
|
|
|
int aclcheck_result;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
|
|
|
#ifndef NO_SECURITY
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
relationName = RewriteGetRuleEventRel(rulename);
|
|
|
|
aclcheck_result = pg_aclcheck(relationName, userName, ACL_RU);
|
|
|
|
if (aclcheck_result != ACLCHECK_OK)
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relationName, aclcheck_error_strings[aclcheck_result]);
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
RemoveRewriteRule(rulename);
|
|
|
|
}
|
|
|
|
break;
|
1997-10-25 07:34:07 +02:00
|
|
|
case TYPE_P:
|
1997-09-07 07:04:48 +02:00
|
|
|
#ifndef NO_SECURITY
|
1997-09-08 04:41:22 +02:00
|
|
|
/* XXX moved to remove.c */
|
1997-09-07 07:04:48 +02:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
RemoveType(stmt->name);
|
|
|
|
break;
|
|
|
|
case VIEW:
|
|
|
|
{
|
|
|
|
char *viewName = stmt->name;
|
|
|
|
char *ruleName;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
#ifndef NO_SECURITY
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
ruleName = MakeRetrieveViewRuleName(viewName);
|
|
|
|
relationName = RewriteGetRuleEventRel(ruleName);
|
|
|
|
if (!pg_ownercheck(userName, relationName, RELNAME))
|
1998-01-05 17:40:20 +01:00
|
|
|
elog(ERROR, "%s: %s", relationName, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
1997-09-08 04:41:22 +02:00
|
|
|
pfree(ruleName);
|
1996-07-09 08:22:35 +02:00
|
|
|
#endif
|
1997-09-08 04:41:22 +02:00
|
|
|
RemoveView(viewName);
|
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
1997-05-22 02:17:24 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RemoveAggrStmt:
|
|
|
|
{
|
|
|
|
RemoveAggrStmt *stmt = (RemoveAggrStmt *) parsetree;
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
RemoveAggregate(stmt->aggname, stmt->aggtype);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
RemoveFunction(stmt->funcname,
|
|
|
|
length(stmt->args),
|
|
|
|
stmt->args);
|
|
|
|
}
|
|
|
|
break;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
case T_RemoveOperStmt:
|
|
|
|
{
|
|
|
|
RemoveOperStmt *stmt = (RemoveOperStmt *) parsetree;
|
|
|
|
char *type1 = (char *) NULL;
|
|
|
|
char *type2 = (char *) NULL;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1996-07-09 08:22:35 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
if (lfirst(stmt->args) != NULL)
|
|
|
|
type1 = strVal(lfirst(stmt->args));
|
|
|
|
if (lsecond(stmt->args) != NULL)
|
|
|
|
type2 = strVal(lsecond(stmt->args));
|
|
|
|
RemoveOperator(stmt->opname, type1, type2);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
1999-12-10 04:56:14 +01:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE DATABASE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
2000-01-13 19:26:18 +01:00
|
|
|
createdb(stmt->dbname, stmt->dbpath, 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
|
|
|
|
1999-12-10 04:56:14 +01:00
|
|
|
PS_SET_STATUS(commandTag = "DROP DATABASE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "NOTIFY");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "LISTEN");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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;
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "UNLISTEN");
|
1998-08-25 23:37:08 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
Async_Unlisten(stmt->relname, MyProcPid);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
/*
|
|
|
|
* ******************************** dynamic loader ********************************
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_LoadStmt:
|
|
|
|
{
|
|
|
|
LoadStmt *stmt = (LoadStmt *) parsetree;
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "LOAD");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CLUSTER");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
cluster(stmt->relname, stmt->indexname);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VacuumStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "VACUUM");
|
1997-09-07 07:04:48 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-08 04:41:22 +02:00
|
|
|
vacuum(((VacuumStmt *) parsetree)->vacrel,
|
|
|
|
((VacuumStmt *) parsetree)->verbose,
|
|
|
|
((VacuumStmt *) parsetree)->analyze,
|
|
|
|
((VacuumStmt *) parsetree)->va_spec);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_ExplainStmt:
|
|
|
|
{
|
|
|
|
ExplainStmt *stmt = (ExplainStmt *) parsetree;
|
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "EXPLAIN");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1997-09-08 04:41:22 +02:00
|
|
|
ExplainQuery(stmt->query, stmt->verbose, dest);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "EXECUTE RECIPE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
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);
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "SET VARIABLE");
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VariableShowStmt:
|
|
|
|
{
|
|
|
|
VariableShowStmt *n = (VariableShowStmt *) parsetree;
|
|
|
|
|
|
|
|
GetPGVariable(n->name);
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "SHOW VARIABLE");
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_VariableResetStmt:
|
|
|
|
{
|
|
|
|
VariableResetStmt *n = (VariableResetStmt *) parsetree;
|
|
|
|
|
|
|
|
ResetPGVariable(n->name);
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "RESET VARIABLE");
|
1997-09-08 04:41:22 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ******************************** TRIGGER statements *******************************
|
|
|
|
*/
|
|
|
|
case T_CreateTrigStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-09-08 04:41:22 +02:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
CreateTrigger((CreateTrigStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DropTrigStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-09-07 07:04:48 +02:00
|
|
|
CHECK_IF_ABORTED();
|
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:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE");
|
1997-10-28 16:11:45 +01:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
CreateProceduralLanguage((CreatePLangStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case T_DropPLangStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP");
|
1997-10-28 16:11:45 +01:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
DropProceduralLanguage((DropPLangStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
1998-02-26 05:46:47 +01:00
|
|
|
/*
|
|
|
|
* ******************************** USER statements ****
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
case T_CreateUserStmt:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "CREATE USER");
|
1998-02-26 05:46:47 +01:00
|
|
|
CHECK_IF_ABORTED();
|
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:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "ALTER USER");
|
1998-02-26 05:46:47 +01:00
|
|
|
CHECK_IF_ABORTED();
|
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:
|
1998-09-01 06:40:42 +02:00
|
|
|
PS_SET_STATUS(commandTag = "DROP USER");
|
1998-02-26 05:46:47 +01:00
|
|
|
CHECK_IF_ABORTED();
|
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:
|
|
|
|
PS_SET_STATUS(commandTag = "LOCK TABLE");
|
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
LockTableCommand((LockStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
1999-09-29 18:06:40 +02:00
|
|
|
case T_ConstraintsSetStmt:
|
|
|
|
PS_SET_STATUS(commandTag = "SET CONSTRAINTS");
|
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
DeferredTriggerSetState((ConstraintsSetStmt *) parsetree);
|
|
|
|
break;
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
case T_CreateGroupStmt:
|
|
|
|
PS_SET_STATUS(commandTag = "CREATE GROUP");
|
1999-12-16 18:24:19 +01:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
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:
|
|
|
|
PS_SET_STATUS(commandTag = "ALTER GROUP");
|
1999-12-16 18:24:19 +01:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
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:
|
|
|
|
PS_SET_STATUS(commandTag = "DROP GROUP");
|
1999-12-16 18:24:19 +01:00
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
2000-04-12 19:17:23 +02:00
|
|
|
DropGroup((DropGroupStmt *) parsetree);
|
|
|
|
break;
|
1997-12-04 01:28:15 +01:00
|
|
|
|
2000-02-18 10:30:20 +01:00
|
|
|
case T_ReindexStmt:
|
|
|
|
{
|
|
|
|
ReindexStmt *stmt = (ReindexStmt *) parsetree;
|
|
|
|
|
|
|
|
PS_SET_STATUS(commandTag = "REINDEX");
|
|
|
|
CHECK_IF_ABORTED();
|
|
|
|
|
|
|
|
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-12 19:17:23 +02:00
|
|
|
elog(ERROR, "class \"%s\" is a system catalog index",
|
|
|
|
relname);
|
2000-02-18 10:30:20 +01:00
|
|
|
if (!IsIgnoringSystemIndexes())
|
|
|
|
elog(ERROR, "class \"%s\" is a system catalog index",
|
2000-04-12 19:17:23 +02:00
|
|
|
relname);
|
2000-02-18 10:30:20 +01:00
|
|
|
}
|
|
|
|
#ifndef NO_SECURITY
|
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
|
|
|
#endif
|
|
|
|
ReindexIndex(relname, stmt->force);
|
|
|
|
break;
|
|
|
|
case TABLE:
|
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-12 19:17:23 +02:00
|
|
|
elog(ERROR, "class \"%s\" is a system catalog index",
|
|
|
|
relname);
|
2000-02-18 10:30:20 +01:00
|
|
|
if (!IsIgnoringSystemIndexes())
|
|
|
|
elog(ERROR, "class \"%s\" is a system catalog index",
|
2000-04-12 19:17:23 +02:00
|
|
|
relname);
|
2000-02-18 10:30:20 +01:00
|
|
|
}
|
|
|
|
#ifndef NO_SECURITY
|
|
|
|
if (!pg_ownercheck(userName, relname, RELNAME))
|
|
|
|
elog(ERROR, "%s: %s", relname, aclcheck_error_strings[ACLCHECK_NOT_OWNER]);
|
|
|
|
#endif
|
|
|
|
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)
|
|
|
|
elog(ERROR, "-O option is needed");
|
|
|
|
if (!IsIgnoringSystemIndexes())
|
|
|
|
elog(ERROR, "-P option is needed");
|
|
|
|
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
|
|
|
|
|
|
|
/* ----------------
|
|
|
|
* 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
|
|
|
}
|