ALTER GROUP
- add users to a group or remove users from a group
+ change a user group
ALTER GROUP groupname ADD USER username [, ... ]
ALTER GROUP groupname DROP USER username [, ... ]
+
+ALTER GROUP groupname RENAME TO newname
Description
- ALTER GROUP is used to add or remove users from a
- group. Only database superusers can use this command.
- Adding a user to a group does not create the user. Similarly, removing
- a user from a group does not drop the user itself.
+ ALTER GROUP is used to change a user group. The
+ first two variants add or remove users from a group. Only database
+ superusers can use this command. Adding a user to a group does not
+ create the user. Similarly, removing a user from a group does not
+ drop the user itself.
- Use
- to create a new group and
- endterm="SQL-DROPGROUP-title"> to remove a group.
+ The third variant changes the name of the group. Only a database
+ superuser can rename groups.
+
+
+ newname
+
+ The new name of the group.
+
+
+
standard. The concept of roles is similar.
+
+
+
See Also
+
+
+
+
+
+
+
+
+
+
+ ALTER LANGUAGE
+ SQL - Language Statements
+
+
+
+ ALTER LANGUAGE
+ change the definition of a procedural language
+
+
+
+
+ALTER LANGUAGE name RENAME TO newname
+
+
+
+
+
Description
+
+ ALTER LANGUAGE changes the definition of a
+ language. The only functionality is to rename the language. Only
+ a superuser can rename languages.
+
+
+
+
+
Parameter
+
+
+
+ name
+
+ Name of a language
+
+
+
+
+
+ newname
+
+ The new name of the language
+
+
+
+
+
+
+
+
Diagnostics
+
+
+
+ ALTER LANGUAGE
+
+ Message returned if the alteration was successful.
+
+
+
+
+
+
+
+
Compatibility
+
+ There is no ALTER LANGUAGE statement in the SQL
+ standard.
+
+
+
+
+
See Also
+
+
+
+
+
+
+
+
+
+
--- /dev/null
+
+
+
+
+ ALTER OPERATOR CLASS
+ SQL - Language Statements
+
+
+
+ ALTER OPERATOR CLASS
+ change the definition of an operator class
+
+
+
+
+ALTER OPERATOR CLASS name USING index_method RENAME TO newname
+
+
+
+
+
Description
+
+ ALTER OPERATOR CLASS changes the definition of
+ an operator class. The only functionality is to rename the
+ operator class.
+
+
+
+
+
Parameters
+
+
+
+ name
+
+ The name (optionally schema-qualified) of an existing operator
+ class.
+
+
+
+
+
+ index_method
+
+ The name of the index method this operator class is for.
+
+
+
+
+
+ newname
+
+ The new name of the operator class.
+
+
+
+
+
+
+
+
Diagnostics
+
+
+
+ ALTER OPERATOR CLASS
+
+ Message returned if the command was successful.
+
+
+
+
+
+
+
+
Compatibility
+
+ There is no ALTER OPERATOR CLASS statement in
+ the SQL standard.
+
+
+
+
+
See Also
+
+
+
+
+
+
+
+
+
--- /dev/null
+
+
+
+
+ ALTER SCHEMA
+ SQL - Schema Statements
+
+
+
+ ALTER SCHEMA
+ change the definition of a schema
+
+
+
+
+ALTER SCHEMA name RENAME TO newname
+
+
+
+
+
Description
+
+ ALTER SCHEMA changes the definition of a schema.
+ The only functionality is to rename the schema. To rename a schema
+ you must own the schema and have the privilege
+ CREATE for the database.
+
+
+
+
+
Parameter
+
+
+
+ name
+
+ Name of a schema
+
+
+
+
+
+ newname
+
+ The new name of the schema
+
+
+
+
+
+
+
+
Diagnostics
+
+
+
+ ALTER SCHEMA
+
+ Message returned if the alteration was successful.
+
+
+
+
+
+
+
+
Compatibility
+
+ There is no ALTER SCHEMA statement in the SQL
+ standard.
+
+
+
+
+
See Also
+
+
+
+
+
+
+
+
+
+
| CREATEUSER | NOCREATEUSER
| VALID UNTIL 'abstime'
+ALTER USER username RENAME TO newname
+
ALTER USER username SET variable { TO | = } { value | DEFAULT }
ALTER USER username RESET variable
- The second and the third variant change a user's session default for
+ The second variant changes the name of the user. Only a database
+ superuser can rename user accounts. The session user cannot be
+ renamed. (Connect as a different user if you need to do that.)
+
+
+ The third and the fourth variant change a user's session default for
a specified configuration variable. Whenever the user subsequently
starts a new session, the specified value becomes the session default,
overriding whatever setting is present in postgresql.conf>
+
+ newname
+
+ The new name of the user.
+
+
+
+
variable
value
-
-
Notes
-
- Use DROP AGGREGATE to drop aggregate functions.
-
-
-
Examples
standard does not provide for user-defined aggregate function.
+
+
+
See Also
+
+
+
+
+
+
+
See Also
- ,
-
-
+
+
+
+
+
See Also
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
-
-
Notes
-
- Refer to
-
- to delete user-defined operator classes from a database.
-
-
-
Examples
standard.
+
+
+
See Also
+
+
+
+
+
+
privilege for the current database. (Of course, superusers bypass
this check.)
-
- Use DROP SCHEMA to remove a schema.
-
CREATE> privilege on his schema to someone else.
+
+
+
See Also
+
+
+
+
+
+
+
See Also
+
&abort;
+ &alterAggregate;
+ &alterConversion;
&alterDatabase;
&alterDomain;
+ &alterFunction;
&alterGroup;
+ &alterLanguage;
+ &alterOperatorClass;
+ &alterSchema;
&alterSequence;
&alterTable;
&alterTrigger;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.81 2003/05/27 17:49:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.82 2003/06/27 14:45:26 petere Exp $
*
* NOTES
* See acl.h.
return userid == owner_id;
}
+
+
+/*
+ * Ownership check for database (specified as OID)
+ */
+bool
+pg_database_ownercheck(Oid db_oid, AclId userid)
+{
+ Relation pg_database;
+ ScanKeyData entry[1];
+ HeapScanDesc scan;
+ HeapTuple dbtuple;
+ int32 dba;
+
+ /* Superusers bypass all permission checking. */
+ if (superuser_arg(userid))
+ return true;
+
+ /* There's no syscache for pg_database, so must look the hard way */
+ pg_database = heap_openr(DatabaseRelationName, AccessShareLock);
+ ScanKeyEntryInitialize(&entry[0], 0x0,
+ ObjectIdAttributeNumber, F_OIDEQ,
+ ObjectIdGetDatum(db_oid));
+ scan = heap_beginscan(pg_database, SnapshotNow, 1, entry);
+
+ dbtuple = heap_getnext(scan, ForwardScanDirection);
+
+ if (!HeapTupleIsValid(dbtuple))
+ elog(ERROR, "database %u does not exist", db_oid);
+
+ dba = ((Form_pg_database) GETSTRUCT(dbtuple))->datdba;
+
+ heap_endscan(scan);
+ heap_close(pg_database, AccessShareLock);
+
+ return userid == dba;
+}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.51 2003/05/14 03:26:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.52 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
*/
if (relation->catalogname)
{
- if (strcmp(relation->catalogname, DatabaseName) != 0)
+ if (strcmp(relation->catalogname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented");
}
*/
if (newRelation->catalogname)
{
- if (strcmp(newRelation->catalogname, DatabaseName) != 0)
+ if (strcmp(newRelation->catalogname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented");
}
/*
* We check the catalog name and then ignore it.
*/
- if (strcmp(catalogname, DatabaseName) != 0)
+ if (strcmp(catalogname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented");
break;
default:
if (pg_database_aclcheck(MyDatabaseId, GetSessionUserId(),
ACL_CREATE_TEMP) != ACLCHECK_OK)
elog(ERROR, "%s: not authorized to create temp tables",
- DatabaseName);
+ get_database_name(MyDatabaseId));
snprintf(namespaceName, sizeof(namespaceName), "pg_temp_%d", MyBackendId);
# Makefile for backend/commands
#
# IDENTIFICATION
-# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.31 2002/08/27 04:55:07 tgl Exp $
+# $Header: /cvsroot/pgsql/src/backend/commands/Makefile,v 1.32 2003/06/27 14:45:27 petere Exp $
#
#-------------------------------------------------------------------------
top_builddir = ../../..
include $(top_builddir)/src/Makefile.global
-OBJS = aggregatecmds.o analyze.o async.o cluster.o comment.o \
+OBJS = aggregatecmds.o alter.o analyze.o async.o cluster.o comment.o \
conversioncmds.o copy.o \
dbcommands.o define.o explain.o functioncmds.o \
indexcmds.o lockcmds.o operatorcmds.o opclasscmds.o \
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v 1.7 2003/06/25 21:30:26 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/aggregatecmds.c,v 1.8 2003/06/27 14:45:27 petere Exp $
*
* DESCRIPTION
* The "DefineFoo" routines take the parse tree and pick out the
#include "access/heapam.h"
#include "catalog/catname.h"
#include "catalog/dependency.h"
+#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_aggregate.h"
#include "catalog/pg_proc.h"
performDeletion(&object, stmt->behavior);
}
+
+
+void
+RenameAggregate(List *name, TypeName *basetype, const char *newname)
+{
+ Oid basetypeOid;
+ Oid procOid;
+ Oid namespaceOid;
+ Oid oid_array[FUNC_MAX_ARGS];
+ HeapTuple tup;
+ Relation rel;
+ AclResult aclresult;
+
+ /*
+ * if a basetype is passed in, then attempt to find an aggregate for
+ * that specific type.
+ *
+ * else attempt to find an aggregate with a basetype of ANYOID. This
+ * means that the aggregate is to apply to all basetypes (eg, COUNT).
+ */
+ if (basetype)
+ basetypeOid = typenameTypeId(basetype);
+ else
+ basetypeOid = ANYOID;
+
+ rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
+
+ procOid = find_aggregate_func("RenameAggregate", name, basetypeOid);
+
+ tup = SearchSysCacheCopy(PROCOID,
+ ObjectIdGetDatum(procOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "RenameAggregate: couldn't find pg_proc tuple for %s",
+ NameListToString(name));
+
+ namespaceOid = ((Form_pg_proc) GETSTRUCT(tup))->pronamespace;
+
+ /* make sure the new name doesn't exist */
+ MemSet(oid_array, 0, sizeof(oid_array));
+ oid_array[0] = basetypeOid;
+ if (SearchSysCacheExists(PROCNAMENSP,
+ CStringGetDatum(newname),
+ Int16GetDatum(1),
+ PointerGetDatum(oid_array),
+ ObjectIdGetDatum(namespaceOid)))
+ {
+ if (basetypeOid == ANYOID)
+ elog(ERROR, "function %s(*) already exists in schema %s",
+ newname, get_namespace_name(namespaceOid));
+ else
+ elog(ERROR, "function %s(%s) already exists in schema %s",
+ newname, format_type_be(basetypeOid), get_namespace_name(namespaceOid));
+ }
+
+ /* must be owner */
+ if (!pg_proc_ownercheck(procOid, GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(name));
+
+ /* must have CREATE privilege on namespace */
+ aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, get_namespace_name(namespaceOid));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_proc) GETSTRUCT(tup))->proname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * alter.c
+ * Drivers for generic alter commands
+ *
+ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ *
+ * IDENTIFICATION
+ * $Header: /cvsroot/pgsql/src/backend/commands/alter.c,v 1.1 2003/06/27 14:45:27 petere Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#include "postgres.h"
+
+#include "access/htup.h"
+#include "catalog/catalog.h"
+#include "catalog/namespace.h"
+#include "catalog/pg_class.h"
+#include "commands/alter.h"
+#include "commands/conversioncmds.h"
+#include "commands/dbcommands.h"
+#include "commands/defrem.h"
+#include "commands/proclang.h"
+#include "commands/schemacmds.h"
+#include "commands/tablecmds.h"
+#include "commands/trigger.h"
+#include "commands/user.h"
+#include "miscadmin.h"
+#include "parser/parse_clause.h"
+#include "utils/acl.h"
+#include "utils/lsyscache.h"
+#include "utils/syscache.h"
+
+
+static void
+CheckOwnership(RangeVar *rel, bool noCatalogs)
+{
+ Oid relOid;
+ HeapTuple tuple;
+
+ relOid = RangeVarGetRelid(rel, false);
+ tuple = SearchSysCache(RELOID,
+ ObjectIdGetDatum(relOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tuple))
+ elog(ERROR, "Relation \"%s\" does not exist", rel->relname);
+
+ if (!pg_class_ownercheck(relOid, GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, rel->relname);
+
+ if (noCatalogs)
+ {
+ if (!allowSystemTableMods &&
+ IsSystemClass((Form_pg_class) GETSTRUCT(tuple)))
+ elog(ERROR, "relation \"%s\" is a system catalog",
+ rel->relname);
+ }
+
+ ReleaseSysCache(tuple);
+}
+
+
+void
+ExecRenameStmt(RenameStmt *stmt)
+{
+ switch (stmt->renameType)
+ {
+ case OBJECT_AGGREGATE:
+ RenameAggregate(stmt->object, (TypeName *) lfirst(stmt->objarg), stmt->newname);
+ break;
+
+ case OBJECT_CONVERSION:
+ RenameConversion(stmt->object, stmt->newname);
+ break;
+
+ case OBJECT_DATABASE:
+ RenameDatabase(stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_FUNCTION:
+ RenameFunction(stmt->object, stmt->objarg, stmt->newname);
+ break;
+
+ case OBJECT_GROUP:
+ RenameGroup(stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_LANGUAGE:
+ RenameLanguage(stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_OPCLASS:
+ RenameOpClass(stmt->object, stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_SCHEMA:
+ RenameSchema(stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_USER:
+ RenameUser(stmt->subname, stmt->newname);
+ break;
+
+ case OBJECT_TABLE:
+ case OBJECT_COLUMN:
+ case OBJECT_TRIGGER:
+ {
+ Oid relid;
+
+ CheckOwnership(stmt->relation, true);
+
+ relid = RangeVarGetRelid(stmt->relation, false);
+
+ switch (stmt->renameType)
+ {
+ case OBJECT_TABLE:
+ {
+ /*
+ * RENAME TABLE requires that we (still) hold
+ * CREATE rights on the containing namespace, as
+ * well as ownership of the table.
+ */
+ Oid namespaceId = get_rel_namespace(relid);
+ AclResult aclresult;
+
+ aclresult = pg_namespace_aclcheck(namespaceId,
+ GetUserId(),
+ ACL_CREATE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult,
+ get_namespace_name(namespaceId));
+
+ renamerel(relid, stmt->newname);
+ break;
+ }
+ case OBJECT_COLUMN:
+ renameatt(relid,
+ stmt->subname, /* old att name */
+ stmt->newname, /* new att name */
+ interpretInhOption(stmt->relation->inhOpt), /* recursive? */
+ false); /* recursing already? */
+ break;
+ case OBJECT_TRIGGER:
+ renametrig(relid,
+ stmt->subname, /* old att name */
+ stmt->newname); /* new att name */
+ break;
+ default:
+ /*can't happen*/;
+ }
+ break;
+ }
+
+ default:
+ elog(ERROR, "invalid object type for RenameStmt: %d", stmt->renameType);
+ }
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.54 2003/05/27 17:49:45 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/analyze.c,v 1.55 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
onerel = relation_open(relid, AccessShareLock);
if (!(pg_class_ownercheck(RelationGetRelid(onerel), GetUserId()) ||
- (is_dbadmin(MyDatabaseId) && !onerel->rd_rel->relisshared)))
+ (pg_database_ownercheck(MyDatabaseId, GetUserId()) && !onerel->rd_rel->relisshared)))
{
/* No need for a WARNING if we already complained during VACUUM */
if (!vacstmt->vacuum)
* Copyright (c) 1996-2001, PostgreSQL Global Development Group
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.62 2003/03/10 22:28:18 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.63 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
{
switch (stmt->objtype)
{
- case COMMENT_ON_INDEX:
- case COMMENT_ON_SEQUENCE:
- case COMMENT_ON_TABLE:
- case COMMENT_ON_VIEW:
+ case OBJECT_INDEX:
+ case OBJECT_SEQUENCE:
+ case OBJECT_TABLE:
+ case OBJECT_VIEW:
CommentRelation(stmt->objtype, stmt->objname, stmt->comment);
break;
- case COMMENT_ON_COLUMN:
+ case OBJECT_COLUMN:
CommentAttribute(stmt->objname, stmt->comment);
break;
- case COMMENT_ON_DATABASE:
+ case OBJECT_DATABASE:
CommentDatabase(stmt->objname, stmt->comment);
break;
- case COMMENT_ON_RULE:
+ case OBJECT_RULE:
CommentRule(stmt->objname, stmt->comment);
break;
- case COMMENT_ON_TYPE:
+ case OBJECT_TYPE:
CommentType(stmt->objname, stmt->comment);
break;
- case COMMENT_ON_AGGREGATE:
+ case OBJECT_AGGREGATE:
CommentAggregate(stmt->objname, stmt->objargs, stmt->comment);
break;
- case COMMENT_ON_FUNCTION:
+ case OBJECT_FUNCTION:
CommentProc(stmt->objname, stmt->objargs, stmt->comment);
break;
- case COMMENT_ON_OPERATOR:
+ case OBJECT_OPERATOR:
CommentOperator(stmt->objname, stmt->objargs, stmt->comment);
break;
- case COMMENT_ON_TRIGGER:
+ case OBJECT_TRIGGER:
CommentTrigger(stmt->objname, stmt->comment);
break;
- case COMMENT_ON_SCHEMA:
+ case OBJECT_SCHEMA:
CommentNamespace(stmt->objname, stmt->comment);
break;
- case COMMENT_ON_CONSTRAINT:
+ case OBJECT_CONSTRAINT:
CommentConstraint(stmt->objname, stmt->comment);
break;
default:
switch (objtype)
{
- case COMMENT_ON_INDEX:
+ case OBJECT_INDEX:
if (relation->rd_rel->relkind != RELKIND_INDEX)
elog(ERROR, "relation \"%s\" is not an index",
RelationGetRelationName(relation));
break;
- case COMMENT_ON_SEQUENCE:
+ case OBJECT_SEQUENCE:
if (relation->rd_rel->relkind != RELKIND_SEQUENCE)
elog(ERROR, "relation \"%s\" is not a sequence",
RelationGetRelationName(relation));
break;
- case COMMENT_ON_TABLE:
+ case OBJECT_TABLE:
if (relation->rd_rel->relkind != RELKIND_RELATION)
elog(ERROR, "relation \"%s\" is not a table",
RelationGetRelationName(relation));
break;
- case COMMENT_ON_VIEW:
+ case OBJECT_VIEW:
if (relation->rd_rel->relkind != RELKIND_VIEW)
elog(ERROR, "relation \"%s\" is not a view",
RelationGetRelationName(relation));
/* Allow if the user matches the database dba or is a superuser */
- if (!(superuser() || is_dbadmin(oid)))
+ if (!pg_database_ownercheck(oid, GetUserId()))
elog(ERROR, "you are not permitted to comment on database \"%s\"",
database);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v 1.5 2002/11/02 02:33:03 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/conversioncmds.c,v 1.6 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "postgres.h"
#include "catalog/pg_conversion.h"
+#include "access/heapam.h"
#include "catalog/catalog.h"
+#include "catalog/catname.h"
+#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_type.h"
#include "mb/pg_wchar.h"
#include "miscadmin.h"
#include "parser/parse_func.h"
#include "utils/acl.h"
+#include "utils/builtins.h"
#include "utils/lsyscache.h"
+#include "utils/syscache.h"
/*
ConversionDrop(conversionOid, behavior);
}
+
+/*
+ * Rename conversion
+ */
+void
+RenameConversion(List *name, const char *newname)
+{
+ Oid conversionOid;
+ Oid namespaceOid;
+ HeapTuple tup;
+ Relation rel;
+ AclResult aclresult;
+
+ rel = heap_openr(ConversionRelationName, RowExclusiveLock);
+
+ conversionOid = FindConversionByName(name);
+ if (!OidIsValid(conversionOid))
+ elog(ERROR, "conversion %s not found", NameListToString(name));
+
+ tup = SearchSysCacheCopy(CONOID,
+ ObjectIdGetDatum(conversionOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "couldn't find pg_conversion tuple for %s",
+ NameListToString(name));
+
+ namespaceOid = ((Form_pg_conversion) GETSTRUCT(tup))->connamespace;
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists(CONNAMENSP,
+ CStringGetDatum(newname),
+ ObjectIdGetDatum(namespaceOid),
+ 0, 0))
+ {
+ elog(ERROR, "conversion %s already exists in schema %s",
+ newname, get_namespace_name(namespaceOid));
+ }
+
+ /* must be owner */
+ if (!superuser() && ((Form_pg_conversion) GETSTRUCT(tup))->conowner != GetUserId())
+ aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(name));
+
+ /* must have CREATE privilege on namespace */
+ aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, get_namespace_name(namespaceOid));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_conversion) GETSTRUCT(tup))->conname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.115 2003/05/15 17:59:17 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/dbcommands.c,v 1.116 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include
#include
+#include "access/genam.h"
#include "access/heapam.h"
#include "catalog/catname.h"
#include "catalog/catalog.h"
#include "miscadmin.h"
#include "storage/freespace.h"
#include "storage/sinval.h"
+#include "utils/acl.h"
#include "utils/array.h"
#include "utils/builtins.h"
#include "utils/fmgroids.h"
char *nominal_loc;
char dbpath[MAXPGPATH];
Relation pgdbrel;
- HeapScanDesc pgdbscan;
+ SysScanDesc pgdbscan;
ScanKeyData key;
HeapTuple tup;
AssertArg(dbname);
- if (strcmp(dbname, DatabaseName) == 0)
+ if (strcmp(dbname, get_database_name(MyDatabaseId)) == 0)
elog(ERROR, "DROP DATABASE: cannot be executed on the currently open database");
PreventTransactionChain((void *) dbname, "DROP DATABASE");
ScanKeyEntryInitialize(&key, 0, ObjectIdAttributeNumber,
F_OIDEQ, ObjectIdGetDatum(db_id));
- pgdbscan = heap_beginscan(pgdbrel, SnapshotNow, 1, &key);
+ pgdbscan = systable_beginscan(pgdbrel, DatabaseOidIndex, true, SnapshotNow, 1, &key);
- tup = heap_getnext(pgdbscan, ForwardScanDirection);
+ tup = systable_getnext(pgdbscan);
if (!HeapTupleIsValid(tup))
{
/*
/* Remove the database's tuple from pg_database */
simple_heap_delete(pgdbrel, &tup->t_self);
- heap_endscan(pgdbscan);
+ systable_endscan(pgdbscan);
/*
* Delete any comments associated with the database
}
+/*
+ * Rename database
+ */
+void
+RenameDatabase(const char *oldname, const char *newname)
+{
+ HeapTuple tup, newtup;
+ Relation rel;
+ SysScanDesc scan, scan2;
+ ScanKeyData key, key2;
+
+ /*
+ * Obtain AccessExclusiveLock so that no new session gets started
+ * while the rename is in progress.
+ */
+ rel = heap_openr(DatabaseRelationName, AccessExclusiveLock);
+
+ ScanKeyEntryInitialize(&key, 0, Anum_pg_database_datname,
+ F_NAMEEQ, NameGetDatum(oldname));
+ scan = systable_beginscan(rel, DatabaseNameIndex, true, SnapshotNow, 1, &key);
+
+ tup = systable_getnext(scan);
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("database \"%s\" does not exist", oldname)));
+
+ /*
+ * XXX Client applications probably store the current database
+ * somewhere, so renaming it could cause confusion. On the other
+ * hand, there may not be an actual problem besides a little
+ * confusion, so think about this and decide.
+ */
+ if (HeapTupleGetOid(tup) == MyDatabaseId)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("current database may not be renamed")));
+
+ /*
+ * Make sure the database does not have active sessions. Might
+ * not be necessary, but it's consistent with other database
+ * operations.
+ */
+ if (DatabaseHasActiveBackends(HeapTupleGetOid(tup), false))
+ elog(ERROR, "database \"%s\" is being accessed by other users", oldname);
+
+ /* make sure the new name doesn't exist */
+ ScanKeyEntryInitialize(&key2, 0, Anum_pg_database_datname,
+ F_NAMEEQ, NameGetDatum(newname));
+ scan2 = systable_beginscan(rel, DatabaseNameIndex, true, SnapshotNow, 1, &key2);
+ if (HeapTupleIsValid(systable_getnext(scan2)))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("database \"%s\" already exists", newname)));
+ }
+ systable_endscan(scan2);
+
+ /* must be owner */
+ if (!pg_database_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, oldname);
+
+ /* must have createdb */
+ if (!have_createdb_privilege())
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("permission denied")));
+ }
+
+ /* rename */
+ newtup = heap_copytuple(tup);
+ namestrcpy(&(((Form_pg_database) GETSTRUCT(newtup))->datname), newname);
+ simple_heap_update(rel, &tup->t_self, newtup);
+ CatalogUpdateIndexes(rel, newtup);
+
+ systable_endscan(scan);
+ heap_close(rel, NoLock);
+
+ /*
+ * Force dirty buffers out to disk, so that newly-connecting
+ * backends will see the renamed database in pg_database right
+ * away. (They'll see an uncommitted tuple, but they don't care;
+ * see GetRawDatabaseInfo.)
+ */
+ BufferSync();
+}
+
/*
* ALTER DATABASE name SET ...
newtuple;
Relation rel;
ScanKeyData scankey;
- HeapScanDesc scan;
+ SysScanDesc scan;
Datum repl_val[Natts_pg_database];
char repl_null[Natts_pg_database];
char repl_repl[Natts_pg_database];
rel = heap_openr(DatabaseRelationName, RowExclusiveLock);
ScanKeyEntryInitialize(&scankey, 0, Anum_pg_database_datname,
F_NAMEEQ, NameGetDatum(stmt->dbname));
- scan = heap_beginscan(rel, SnapshotNow, 1, &scankey);
- tuple = heap_getnext(scan, ForwardScanDirection);
+ scan = systable_beginscan(rel, DatabaseNameIndex, true, SnapshotNow, 1, &scankey);
+ tuple = systable_getnext(scan);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "database \"%s\" does not exist", stmt->dbname);
/* Update indexes */
CatalogUpdateIndexes(rel, newtuple);
- heap_endscan(scan);
+ systable_endscan(scan);
heap_close(rel, RowExclusiveLock);
}
{
Relation relation;
ScanKeyData scanKey;
- HeapScanDesc scan;
+ SysScanDesc scan;
HeapTuple tuple;
bool gottuple;
ScanKeyEntryInitialize(&scanKey, 0, Anum_pg_database_datname,
F_NAMEEQ, NameGetDatum(name));
- scan = heap_beginscan(relation, SnapshotNow, 1, &scanKey);
+ scan = systable_beginscan(relation, DatabaseNameIndex, true, SnapshotNow, 1, &scanKey);
- tuple = heap_getnext(scan, ForwardScanDirection);
+ tuple = systable_getnext(scan);
gottuple = HeapTupleIsValid(tuple);
if (gottuple)
}
}
- heap_endscan(scan);
+ systable_endscan(scan);
heap_close(relation, AccessShareLock);
return gottuple;
{
Relation pg_database;
ScanKeyData entry[1];
- HeapScanDesc scan;
+ SysScanDesc scan;
HeapTuple dbtuple;
Oid oid;
ScanKeyEntryInitialize(&entry[0], 0x0,
Anum_pg_database_datname, F_NAMEEQ,
CStringGetDatum(dbname));
- scan = heap_beginscan(pg_database, SnapshotNow, 1, entry);
+ scan = systable_beginscan(pg_database, DatabaseNameIndex, true, SnapshotNow, 1, entry);
- dbtuple = heap_getnext(scan, ForwardScanDirection);
+ dbtuple = systable_getnext(scan);
/* We assume that there can be at most one matching tuple */
if (HeapTupleIsValid(dbtuple))
else
oid = InvalidOid;
- heap_endscan(scan);
+ systable_endscan(scan);
heap_close(pg_database, AccessShareLock);
return oid;
}
+
/*
- * get_database_owner - given a database OID, fetch the owner's usesysid.
+ * get_database_name - given a database OID, look up the name
*
- * Errors out if database not found.
+ * Returns InvalidOid if database name not found.
*
* This is not actually used in this file, but is exported for use elsewhere.
*/
-Oid
-get_database_owner(Oid dbid)
+char *
+get_database_name(Oid dbid)
{
Relation pg_database;
ScanKeyData entry[1];
- HeapScanDesc scan;
+ SysScanDesc scan;
HeapTuple dbtuple;
- int32 dba;
+ char *result;
/* There's no syscache for pg_database, so must look the hard way */
pg_database = heap_openr(DatabaseRelationName, AccessShareLock);
ScanKeyEntryInitialize(&entry[0], 0x0,
ObjectIdAttributeNumber, F_OIDEQ,
ObjectIdGetDatum(dbid));
- scan = heap_beginscan(pg_database, SnapshotNow, 1, entry);
+ scan = systable_beginscan(pg_database, DatabaseOidIndex, true, SnapshotNow, 1, entry);
- dbtuple = heap_getnext(scan, ForwardScanDirection);
+ dbtuple = systable_getnext(scan);
- if (!HeapTupleIsValid(dbtuple))
- elog(ERROR, "database %u does not exist", dbid);
-
- dba = ((Form_pg_database) GETSTRUCT(dbtuple))->datdba;
+ /* We assume that there can be at most one matching tuple */
+ if (HeapTupleIsValid(dbtuple))
+ result = pstrdup(NameStr(((Form_pg_database) GETSTRUCT(dbtuple))->datname));
+ else
+ result = NULL;
- heap_endscan(scan);
+ systable_endscan(scan);
heap_close(pg_database, AccessShareLock);
- /* XXX some confusion about whether userids are OID or int4 ... */
- return (Oid) dba;
+ return result;
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.25 2003/02/01 22:09:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/functioncmds.c,v 1.26 2003/06/27 14:45:27 petere Exp $
*
* DESCRIPTION
* These routines take the parse tree and pick out the
}
+/*
+ * Rename function
+ */
+void
+RenameFunction(List *name, List *argtypes, const char *newname)
+{
+ Oid procOid;
+ Oid namespaceOid;
+ Oid oid_array[FUNC_MAX_ARGS];
+ HeapTuple tup;
+ Relation rel;
+ AclResult aclresult;
+ int16 nargs;
+
+ rel = heap_openr(ProcedureRelationName, RowExclusiveLock);
+
+ procOid = LookupFuncNameTypeNames(name, argtypes, "RenameFunction");
+
+ tup = SearchSysCacheCopy(PROCOID,
+ ObjectIdGetDatum(procOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "RenameFunction: couldn't find pg_proc tuple for %s",
+ NameListToString(name));
+
+ if (((Form_pg_proc) GETSTRUCT(tup))->proisagg)
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("%s is an aggregate function", NameListToString(name)),
+ errhint("Use ALTER AGGREGATE to rename aggregate functions.")));
+
+ namespaceOid = ((Form_pg_proc) GETSTRUCT(tup))->pronamespace;
+
+ /* make sure the new name doesn't exist */
+ nargs = compute_parameter_types(argtypes, ((Form_pg_proc) GETSTRUCT(tup))->prolang, oid_array);
+ if (SearchSysCacheExists(PROCNAMENSP,
+ CStringGetDatum(newname),
+ Int16GetDatum(nargs),
+ PointerGetDatum(oid_array),
+ ObjectIdGetDatum(namespaceOid)))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("function %s with the same argument types already exists in schema %s",
+ newname, get_namespace_name(namespaceOid))));
+ }
+
+ /* must be owner */
+ if (!pg_proc_ownercheck(procOid, GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(name));
+
+ /* must have CREATE privilege on namespace */
+ aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, get_namespace_name(namespaceOid));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_proc) GETSTRUCT(tup))->proname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
+
+
/*
* SetFunctionReturnType - change declared return type of a function
*
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.100 2003/05/28 16:03:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/indexcmds.c,v 1.101 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "catalog/namespace.h"
#include "catalog/pg_opclass.h"
#include "catalog/pg_proc.h"
+#include "commands/dbcommands.h"
#include "commands/defrem.h"
#include "commands/tablecmds.h"
#include "executor/executor.h"
AssertArg(dbname);
- if (strcmp(dbname, DatabaseName) != 0)
+ if (strcmp(dbname, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "REINDEX DATABASE: Can be executed only on the currently open database.");
- if (!(superuser() || is_dbadmin(MyDatabaseId)))
+ if (!pg_database_ownercheck(MyDatabaseId, GetUserId()))
elog(ERROR, "REINDEX DATABASE: Permission denied.");
if (!allowSystemTableMods)
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.9 2002/11/13 00:39:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/opclasscmds.c,v 1.10 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
ObjectIdGetDatum(opclassOid),
0, 0, 0);
if (!HeapTupleIsValid(tup)) /* should not happen */
- elog(ERROR, "RemoveOpClassById: couldn't find pg_class entry %u",
+ elog(ERROR, "RemoveOpClassById: couldn't find pg_opclass entry %u",
opclassOid);
simple_heap_delete(rel, &tup->t_self);
systable_endscan(scan);
heap_close(rel, RowExclusiveLock);
}
+
+
+/*
+ * Rename opclass
+ */
+void
+RenameOpClass(List *name, const char *access_method, const char *newname)
+{
+ Oid opcOid;
+ Oid amOid;
+ Oid namespaceOid;
+ char *schemaname;
+ char *opcname;
+ HeapTuple tup;
+ Relation rel;
+ AclResult aclresult;
+
+ amOid = GetSysCacheOid(AMNAME,
+ CStringGetDatum(access_method),
+ 0, 0, 0);
+ if (!OidIsValid(amOid))
+ elog(ERROR, "access method \"%s\" not found", access_method);
+
+ rel = heap_openr(OperatorClassRelationName, RowExclusiveLock);
+
+ /*
+ * Look up the opclass
+ */
+ DeconstructQualifiedName(name, &schemaname, &opcname);
+
+ if (schemaname)
+ {
+ namespaceOid = LookupExplicitNamespace(schemaname);
+
+ tup = SearchSysCacheCopy(CLAAMNAMENSP,
+ ObjectIdGetDatum(amOid),
+ PointerGetDatum(opcname),
+ ObjectIdGetDatum(namespaceOid),
+ 0);
+ if (!HeapTupleIsValid(tup))
+ elog(ERROR, "operator class \"%s\" for access method \"%s\" does not exist",
+ opcname, access_method);
+
+ opcOid = HeapTupleGetOid(tup);
+ }
+ else
+ {
+ opcOid = OpclassnameGetOpcid(amOid, opcname);
+ if (!OidIsValid(opcOid))
+ elog(ERROR, "operator class \"%s\" for access method \"%s\" does not exist",
+ opcname, access_method);
+
+ tup = SearchSysCacheCopy(CLAOID,
+ ObjectIdGetDatum(opcOid),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup)) /* should not happen */
+ elog(ERROR, "couldn't find pg_opclass tuple for %u", opcOid);
+
+ namespaceOid = ((Form_pg_opclass) GETSTRUCT(tup))->opcnamespace;
+ }
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists(CLAAMNAMENSP,
+ ObjectIdGetDatum(amOid),
+ CStringGetDatum(newname),
+ ObjectIdGetDatum(namespaceOid),
+ 0))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("operator class \"%s\" for access method \"%s\" already exists in schema \"%s\"",
+ newname, access_method, get_namespace_name(namespaceOid))));
+ }
+
+ /* must be owner */
+ if (!pg_opclass_ownercheck(opcOid, GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, NameListToString(name));
+
+ /* must have CREATE privilege on namespace */
+ aclresult = pg_namespace_aclcheck(namespaceOid, GetUserId(), ACL_CREATE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, get_namespace_name(namespaceOid));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_opclass) GETSTRUCT(tup))->opcname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.43 2002/09/21 18:39:25 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/proclang.c,v 1.44 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
heap_close(rel, RowExclusiveLock);
}
+
+/*
+ * Rename language
+ */
+void
+RenameLanguage(const char *oldname, const char *newname)
+{
+ HeapTuple tup;
+ Relation rel;
+
+ rel = heap_openr(ShadowRelationName, RowExclusiveLock);
+
+ tup = SearchSysCacheCopy(LANGNAME,
+ CStringGetDatum(oldname),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("language \"%s\" does not exist", oldname)));
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists(LANGNAME,
+ CStringGetDatum(newname),
+ 0, 0, 0))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("language \"%s\" already exists", newname)));
+ }
+
+ /* must be superuser */
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("permission denied")));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_language) GETSTRUCT(tup))->lanname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.9 2003/05/06 20:26:26 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/schemacmds.c,v 1.10 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "catalog/catalog.h"
#include "catalog/catname.h"
#include "catalog/dependency.h"
+#include "catalog/indexing.h"
#include "catalog/namespace.h"
#include "catalog/pg_namespace.h"
+#include "commands/dbcommands.h"
#include "commands/schemacmds.h"
#include "miscadmin.h"
#include "parser/analyze.h"
*/
aclresult = pg_database_aclcheck(MyDatabaseId, saved_userid, ACL_CREATE);
if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult, DatabaseName);
+ aclcheck_error(aclresult, get_database_name(MyDatabaseId));
if (!allowSystemTableMods && IsReservedName(schemaName))
elog(ERROR, "CREATE SCHEMA: Illegal schema name: \"%s\" -- pg_ is reserved for system schemas",
heap_close(relation, RowExclusiveLock);
}
+
+
+/*
+ * Rename schema
+ */
+void
+RenameSchema(const char *oldname, const char *newname)
+{
+ HeapTuple tup;
+ Relation rel;
+ AclResult aclresult;
+
+ rel = heap_openr(NamespaceRelationName, RowExclusiveLock);
+
+ tup = SearchSysCacheCopy(NAMESPACENAME,
+ CStringGetDatum(oldname),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("schema \"%s\" does not exist", oldname)));
+
+ /* make sure the new name doesn't exist */
+ if (HeapTupleIsValid(
+ SearchSysCache(NAMESPACENAME,
+ CStringGetDatum(newname),
+ 0, 0, 0)))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("schema \"%s\" already exists", newname)));
+ }
+
+ /* must be owner */
+ if (!pg_namespace_ownercheck(HeapTupleGetOid(tup), GetUserId()))
+ aclcheck_error(ACLCHECK_NOT_OWNER, oldname);
+
+ /* must have CREATE privilege on database */
+ aclresult = pg_database_aclcheck(MyDatabaseId, GetUserId(), ACL_CREATE);
+ if (aclresult != ACLCHECK_OK)
+ aclcheck_error(aclresult, get_database_name(MyDatabaseId));
+
+ if (!allowSystemTableMods && IsReservedName(newname))
+ elog(ERROR, "illegal schema name: \"%s\" -- pg_ is reserved for system schemas",
+ newname);
+
+ /* rename */
+ namestrcpy(&(((Form_pg_namespace) GETSTRUCT(tup))->nspname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+}
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.117 2003/05/12 23:08:50 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/user.c,v 1.118 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
}
+/*
+ * Rename user
+ */
+void
+RenameUser(const char *oldname, const char *newname)
+{
+ HeapTuple tup;
+ Relation rel;
+
+ /* ExclusiveLock because we need to update the password file */
+ rel = heap_openr(ShadowRelationName, ExclusiveLock);
+
+ tup = SearchSysCacheCopy(SHADOWNAME,
+ CStringGetDatum(oldname),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("user \"%s\" does not exist", oldname)));
+
+ /*
+ * XXX Client applications probably store the session user
+ * somewhere, so renaming it could cause confusion. On the other
+ * hand, there may not be an actual problem besides a little
+ * confusion, so think about this and decide.
+ */
+ if (((Form_pg_shadow) GETSTRUCT(tup))->usesysid == GetSessionUserId())
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("session user may not be renamed")));
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists(SHADOWNAME,
+ CStringGetDatum(newname),
+ 0, 0, 0))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("user \"%s\" already exists", newname)));
+ }
+
+ /* must be superuser */
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("permission denied")));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_shadow) GETSTRUCT(tup))->usename), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+
+ user_file_update_needed = true;
+}
+
/*
* CheckPgUserAclNotNull
*/
group_file_update_needed = true;
}
+
+
+/*
+ * Rename group
+ */
+void
+RenameGroup(const char *oldname, const char *newname)
+{
+ HeapTuple tup;
+ Relation rel;
+
+ /* ExclusiveLock because we need to update the flat group file */
+ rel = heap_openr(GroupRelationName, ExclusiveLock);
+
+ tup = SearchSysCacheCopy(GRONAME,
+ CStringGetDatum(oldname),
+ 0, 0, 0);
+ if (!HeapTupleIsValid(tup))
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("group \"%s\" does not exist", oldname)));
+
+ /* make sure the new name doesn't exist */
+ if (SearchSysCacheExists(GRONAME,
+ CStringGetDatum(newname),
+ 0, 0, 0))
+ {
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("a group \"%s\" already exists", newname)));
+ }
+
+ /* must be superuser */
+ if (!superuser())
+ ereport(ERROR,
+ (errcode(ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION),
+ errmsg("permission denied")));
+
+ /* rename */
+ namestrcpy(&(((Form_pg_group) GETSTRUCT(tup))->groname), newname);
+ simple_heap_update(rel, &tup->t_self, tup);
+ CatalogUpdateIndexes(rel, tup);
+
+ heap_close(rel, NoLock);
+ heap_freetuple(tup);
+
+ group_file_update_needed = true;
+}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.255 2003/05/28 16:03:56 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/commands/vacuum.c,v 1.256 2003/06/27 14:45:27 petere Exp $
*
*-------------------------------------------------------------------------
*/
onerel = relation_open(relid, lmode);
if (!(pg_class_ownercheck(RelationGetRelid(onerel), GetUserId()) ||
- (is_dbadmin(MyDatabaseId) && !onerel->rd_rel->relisshared)))
+ (pg_database_ownercheck(MyDatabaseId, GetUserId()) && !onerel->rd_rel->relisshared)))
{
elog(WARNING, "Skipping \"%s\" --- only table or database owner can VACUUM it",
RelationGetRelationName(onerel));
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.256 2003/06/25 21:30:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.257 2003/06/27 14:45:28 petere Exp $
*
*-------------------------------------------------------------------------
*/
RenameStmt *newnode = makeNode(RenameStmt);
COPY_NODE_FIELD(relation);
- COPY_STRING_FIELD(oldname);
+ COPY_NODE_FIELD(object);
+ COPY_NODE_FIELD(objarg);
+ COPY_STRING_FIELD(subname);
COPY_STRING_FIELD(newname);
COPY_SCALAR_FIELD(renameType);
* Portions Copyright (c) 1994, Regents of the University of California
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.199 2003/06/25 21:30:29 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.200 2003/06/27 14:45:28 petere Exp $
*
*-------------------------------------------------------------------------
*/
_equalRenameStmt(RenameStmt *a, RenameStmt *b)
{
COMPARE_NODE_FIELD(relation);
- COMPARE_STRING_FIELD(oldname);
+ COMPARE_NODE_FIELD(object);
+ COMPARE_NODE_FIELD(objarg);
+ COMPARE_STRING_FIELD(subname);
COMPARE_STRING_FIELD(newname);
COMPARE_SCALAR_FIELD(renameType);
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.421 2003/06/25 21:30:30 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/gram.y,v 2.422 2003/06/27 14:45:28 petere Exp $
*
* HISTORY
* AUTHOR DATE MAJOR EVENT
Node *node;
Value *value;
ColumnRef *columnref;
+ ObjectType objtype;
TypeName *typnam;
DefElem *defelt;
%type copy_from opt_hold
-%type reindex_type drop_type fetch_count
- opt_column event comment_type cursor_options
+%type fetch_count opt_column event cursor_options
+%type reindex_type drop_type comment_type
%type fetch_direction select_limit_value select_offset_value
n->relation = $5;
n->property = $3;
n->behavior = $6;
- n->removeType = DROP_TRIGGER;
+ n->removeType = OBJECT_TRIGGER;
$$ = (Node *) n;
}
;
n->relation = NULL;
n->property = $3;
n->behavior = $4;
- n->removeType = DROP_TRIGGER; /* XXX */
+ n->removeType = OBJECT_TRIGGER; /* XXX */
elog(ERROR, "DROP ASSERTION is not yet supported");
$$ = (Node *) n;
}
CREATE AGGREGATE func_name definition
{
DefineStmt *n = makeNode(DefineStmt);
- n->kind = DEFINE_STMT_AGGREGATE;
+ n->kind = OBJECT_AGGREGATE;
n->defnames = $3;
n->definition = $4;
$$ = (Node *)n;
| CREATE OPERATOR any_operator definition
{
DefineStmt *n = makeNode(DefineStmt);
- n->kind = DEFINE_STMT_OPERATOR;
+ n->kind = OBJECT_OPERATOR;
n->defnames = $3;
n->definition = $4;
$$ = (Node *)n;
| CREATE TYPE_P any_name definition
{
DefineStmt *n = makeNode(DefineStmt);
- n->kind = DEFINE_STMT_TYPE;
+ n->kind = OBJECT_TYPE;
n->defnames = $3;
n->definition = $4;
$$ = (Node *)n;
}
;
-drop_type: TABLE { $$ = DROP_TABLE; }
- | SEQUENCE { $$ = DROP_SEQUENCE; }
- | VIEW { $$ = DROP_VIEW; }
- | INDEX { $$ = DROP_INDEX; }
- | TYPE_P { $$ = DROP_TYPE; }
- | DOMAIN_P { $$ = DROP_DOMAIN; }
- | CONVERSION_P { $$ = DROP_CONVERSION; }
- | SCHEMA { $$ = DROP_SCHEMA; }
+drop_type: TABLE { $$ = OBJECT_TABLE; }
+ | SEQUENCE { $$ = OBJECT_SEQUENCE; }
+ | VIEW { $$ = OBJECT_VIEW; }
+ | INDEX { $$ = OBJECT_INDEX; }
+ | TYPE_P { $$ = OBJECT_TYPE; }
+ | DOMAIN_P { $$ = OBJECT_DOMAIN; }
+ | CONVERSION_P { $$ = OBJECT_CONVERSION; }
+ | SCHEMA { $$ = OBJECT_SCHEMA; }
;
any_name_list:
IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_AGGREGATE;
+ n->objtype = OBJECT_AGGREGATE;
n->objname = $4;
n->objargs = makeList1($6);
n->comment = $9;
| COMMENT ON FUNCTION func_name func_args IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_FUNCTION;
+ n->objtype = OBJECT_FUNCTION;
n->objname = $4;
n->objargs = $5;
n->comment = $7;
IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_OPERATOR;
+ n->objtype = OBJECT_OPERATOR;
n->objname = $4;
n->objargs = $6;
n->comment = $9;
| COMMENT ON CONSTRAINT name ON any_name IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_CONSTRAINT;
+ n->objtype = OBJECT_CONSTRAINT;
n->objname = lappend($6, makeString($4));
n->objargs = NIL;
n->comment = $8;
| COMMENT ON RULE name ON any_name IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_RULE;
+ n->objtype = OBJECT_RULE;
n->objname = lappend($6, makeString($4));
n->objargs = NIL;
n->comment = $8;
{
/* Obsolete syntax supported for awhile for compatibility */
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_RULE;
+ n->objtype = OBJECT_RULE;
n->objname = makeList1(makeString($4));
n->objargs = NIL;
n->comment = $6;
| COMMENT ON TRIGGER name ON any_name IS comment_text
{
CommentStmt *n = makeNode(CommentStmt);
- n->objtype = COMMENT_ON_TRIGGER;
+ n->objtype = OBJECT_TRIGGER;
n->objname = lappend($6, makeString($4));
n->objargs = NIL;
n->comment = $8;
;
comment_type:
- COLUMN { $$ = COMMENT_ON_COLUMN; }
- | DATABASE { $$ = COMMENT_ON_DATABASE; }
- | SCHEMA { $$ = COMMENT_ON_SCHEMA; }
- | INDEX { $$ = COMMENT_ON_INDEX; }
- | SEQUENCE { $$ = COMMENT_ON_SEQUENCE; }
- | TABLE { $$ = COMMENT_ON_TABLE; }
- | DOMAIN_P { $$ = COMMENT_ON_TYPE; }
- | TYPE_P { $$ = COMMENT_ON_TYPE; }
- | VIEW { $$ = COMMENT_ON_VIEW; }
+ COLUMN { $$ = OBJECT_COLUMN; }
+ | DATABASE { $$ = OBJECT_DATABASE; }
+ | SCHEMA { $$ = OBJECT_SCHEMA; }
+ | INDEX { $$ = OBJECT_INDEX; }
+ | SEQUENCE { $$ = OBJECT_SEQUENCE; }
+ | TABLE { $$ = OBJECT_TABLE; }
+ | DOMAIN_P { $$ = OBJECT_TYPE; }
+ | TYPE_P { $$ = OBJECT_TYPE; }
+ | VIEW { $$ = OBJECT_VIEW; }
;
comment_text:
| REINDEX DATABASE name opt_force
{
ReindexStmt *n = makeNode(ReindexStmt);
- n->kind = REINDEX_DATABASE;
+ n->kind = OBJECT_DATABASE;
n->name = $3;
n->relation = NULL;
n->force = $4;
;
reindex_type:
- INDEX { $$ = REINDEX_INDEX; }
- | TABLE { $$ = REINDEX_TABLE; }
+ INDEX { $$ = OBJECT_INDEX; }
+ | TABLE { $$ = OBJECT_TABLE; }
;
opt_force: FORCE { $$ = TRUE; }
/*****************************************************************************
*
- * QUERY:
- * rename to
+ * ALTER THING name RENAME TO newname
*
*****************************************************************************/
-RenameStmt: ALTER TABLE relation_expr RENAME opt_column opt_name TO name
+RenameStmt: ALTER AGGREGATE func_name '(' aggr_argtype ')' RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_AGGREGATE;
+ n->object = $3;
+ n->objarg = makeList1($5);
+ n->newname = $9;
+ $$ = (Node *)n;
+ }
+ | ALTER CONVERSION_P any_name RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_CONVERSION;
+ n->object = $3;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
+ | ALTER DATABASE database_name RENAME TO database_name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_DATABASE;
+ n->subname = $3;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
+ | ALTER FUNCTION func_name func_args RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_FUNCTION;
+ n->object = $3;
+ n->objarg = $4;
+ n->newname = $7;
+ $$ = (Node *)n;
+ }
+ | ALTER GROUP_P UserId RENAME TO UserId
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_GROUP;
+ n->subname = $3;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
+ | ALTER LANGUAGE name RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_LANGUAGE;
+ n->subname = $3;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
+ | ALTER OPERATOR CLASS any_name USING access_method RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_OPCLASS;
+ n->object = $4;
+ n->subname = $6;
+ n->newname = $9;
+ $$ = (Node *)n;
+ }
+ | ALTER SCHEMA name RENAME TO name
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_SCHEMA;
+ n->subname = $3;
+ n->newname = $6;
+ $$ = (Node *)n;
+ }
+ | ALTER TABLE relation_expr RENAME opt_column opt_name TO name
{
RenameStmt *n = makeNode(RenameStmt);
n->relation = $3;
- n->oldname = $6;
+ n->subname = $6;
n->newname = $8;
if ($6 == NULL)
- n->renameType = RENAME_TABLE;
+ n->renameType = OBJECT_TABLE;
else
- n->renameType = RENAME_COLUMN;
+ n->renameType = OBJECT_COLUMN;
$$ = (Node *)n;
}
| ALTER TRIGGER name ON relation_expr RENAME TO name
{
RenameStmt *n = makeNode(RenameStmt);
n->relation = $5;
- n->oldname = $3;
+ n->subname = $3;
n->newname = $8;
- n->renameType = RENAME_TRIGGER;
+ n->renameType = OBJECT_TRIGGER;
+ $$ = (Node *)n;
+ }
+ | ALTER USER UserId RENAME TO UserId
+ {
+ RenameStmt *n = makeNode(RenameStmt);
+ n->renameType = OBJECT_USER;
+ n->subname = $3;
+ n->newname = $6;
$$ = (Node *)n;
}
;
n->relation = $5;
n->property = $3;
n->behavior = $6;
- n->removeType = DROP_RULE;
+ n->removeType = OBJECT_RULE;
$$ = (Node *) n;
}
;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.151 2003/06/27 00:33:25 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.152 2003/06/27 14:45:29 petere Exp $
*
*-------------------------------------------------------------------------
*/
/*
* We check the catalog name and then ignore it.
*/
- if (strcmp(name1, DatabaseName) != 0)
+ if (strcmp(name1, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented");
/* Whole-row reference? */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.103 2003/06/25 04:19:24 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/parser/parse_target.c,v 1.104 2003/06/27 14:45:29 petere Exp $
*
*-------------------------------------------------------------------------
*/
* We check the catalog name and then ignore
* it.
*/
- if (strcmp(name1, DatabaseName) != 0)
+ if (strcmp(name1, get_database_name(MyDatabaseId)) != 0)
elog(ERROR, "Cross-database references are not implemented");
schemaname = strVal(lsecond(fields));
relname = strVal(lthird(fields));
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.200 2003/05/06 21:51:41 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/tcop/utility.c,v 1.201 2003/06/27 14:45:30 petere Exp $
*
*-------------------------------------------------------------------------
*/
#include "catalog/catalog.h"
#include "catalog/namespace.h"
#include "catalog/pg_shadow.h"
+#include "commands/alter.h"
#include "commands/async.h"
#include "commands/cluster.h"
#include "commands/comment.h"
switch (stmt->removeType)
{
- case DROP_TABLE:
+ case OBJECT_TABLE:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_RELATION);
RemoveRelation(rel, stmt->behavior);
break;
- case DROP_SEQUENCE:
+ case OBJECT_SEQUENCE:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_SEQUENCE);
RemoveRelation(rel, stmt->behavior);
break;
- case DROP_VIEW:
+ case OBJECT_VIEW:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_VIEW);
RemoveView(rel, stmt->behavior);
break;
- case DROP_INDEX:
+ case OBJECT_INDEX:
rel = makeRangeVarFromNameList(names);
CheckDropPermissions(rel, RELKIND_INDEX);
RemoveIndex(rel, stmt->behavior);
break;
- case DROP_TYPE:
+ case OBJECT_TYPE:
/* RemoveType does its own permissions checks */
RemoveType(names, stmt->behavior);
break;
- case DROP_DOMAIN:
-
- /*
- * RemoveDomain does its own permissions
- * checks
- */
+ case OBJECT_DOMAIN:
+ /* RemoveDomain does its own permissions checks */
RemoveDomain(names, stmt->behavior);
break;
- case DROP_CONVERSION:
+ case OBJECT_CONVERSION:
DropConversionCommand(names, stmt->behavior);
break;
- case DROP_SCHEMA:
-
- /*
- * RemoveSchema does its own permissions
- * checks
- */
+ case OBJECT_SCHEMA:
+ /* RemoveSchema does its own permissions checks */
RemoveSchema(names, stmt->behavior);
break;
+
+ default:
+ elog(ERROR, "invalid object type for DropStmt: %d", stmt->removeType);
}
/*
* schema
*/
case T_RenameStmt:
- {
- RenameStmt *stmt = (RenameStmt *) parsetree;
- Oid relid;
-
- CheckOwnership(stmt->relation, true);
-
- relid = RangeVarGetRelid(stmt->relation, false);
-
- switch (stmt->renameType)
- {
- case RENAME_TABLE:
- {
- /*
- * RENAME TABLE requires that we (still) hold
- * CREATE rights on the containing namespace,
- * as well as ownership of the table.
- */
- Oid namespaceId = get_rel_namespace(relid);
- AclResult aclresult;
-
- aclresult = pg_namespace_aclcheck(namespaceId,
- GetUserId(),
- ACL_CREATE);
- if (aclresult != ACLCHECK_OK)
- aclcheck_error(aclresult,
- get_namespace_name(namespaceId));
-
- renamerel(relid, stmt->newname);
- break;
- }
- case RENAME_COLUMN:
- renameatt(relid,
- stmt->oldname, /* old att name */
- stmt->newname, /* new att name */
- interpretInhOption(stmt->relation->inhOpt), /* recursive? */
- false); /* recursing already? */
- break;
- case RENAME_TRIGGER:
- renametrig(relid,
- stmt->oldname, /* old att name */
- stmt->newname); /* new att name */
- break;
- case RENAME_RULE:
- elog(ERROR, "ProcessUtility: Invalid type for RENAME: %d",
- stmt->renameType);
- break;
- default:
- elog(ERROR, "ProcessUtility: Invalid type for RENAME: %d",
- stmt->renameType);
- }
- }
+ ExecRenameStmt((RenameStmt *) parsetree);
break;
/* various Alter Table forms */
switch (stmt->kind)
{
- case DEFINE_STMT_AGGREGATE:
+ case OBJECT_AGGREGATE:
DefineAggregate(stmt->defnames, stmt->definition);
break;
- case DEFINE_STMT_OPERATOR:
+ case OBJECT_OPERATOR:
DefineOperator(stmt->defnames, stmt->definition);
break;
- case DEFINE_STMT_TYPE:
+ case OBJECT_TYPE:
DefineType(stmt->defnames, stmt->definition);
break;
+ default:
+ elog(ERROR, "invalid object type for DefineStmt: %d", stmt->kind);
}
}
break;
switch (stmt->removeType)
{
- case DROP_RULE:
+ case OBJECT_RULE:
/* RemoveRewriteRule checks permissions */
RemoveRewriteRule(relId, stmt->property,
stmt->behavior);
break;
- case DROP_TRIGGER:
+ case OBJECT_TRIGGER:
/* DropTrigger checks permissions */
DropTrigger(relId, stmt->property,
stmt->behavior);
break;
+ default:
+ elog(ERROR, "invalid object type for DropPropertyStmt: %d", stmt->removeType);
}
}
break;
switch (stmt->kind)
{
- case REINDEX_INDEX:
+ case OBJECT_INDEX:
CheckOwnership(stmt->relation, false);
ReindexIndex(stmt->relation, stmt->force);
break;
- case REINDEX_TABLE:
+ case OBJECT_TABLE:
CheckOwnership(stmt->relation, false);
ReindexTable(stmt->relation, stmt->force);
break;
- case REINDEX_DATABASE:
+ case OBJECT_DATABASE:
ReindexDatabase(stmt->name, stmt->force, false);
break;
+ default:
+ elog(ERROR, "invalid object type for ReindexStmt: %d", stmt->kind);
}
break;
}
case T_DropStmt:
switch (((DropStmt *) parsetree)->removeType)
{
- case DROP_TABLE:
+ case OBJECT_TABLE:
tag = "DROP TABLE";
break;
- case DROP_SEQUENCE:
+ case OBJECT_SEQUENCE:
tag = "DROP SEQUENCE";
break;
- case DROP_VIEW:
+ case OBJECT_VIEW:
tag = "DROP VIEW";
break;
- case DROP_INDEX:
+ case OBJECT_INDEX:
tag = "DROP INDEX";
break;
- case DROP_TYPE:
+ case OBJECT_TYPE:
tag = "DROP TYPE";
break;
- case DROP_DOMAIN:
+ case OBJECT_DOMAIN:
tag = "DROP DOMAIN";
break;
- case DROP_CONVERSION:
+ case OBJECT_CONVERSION:
tag = "DROP CONVERSION";
break;
- case DROP_SCHEMA:
+ case OBJECT_SCHEMA:
tag = "DROP SCHEMA";
break;
default:
break;
case T_RenameStmt:
- if (((RenameStmt *) parsetree)->renameType == RENAME_TRIGGER)
- tag = "ALTER TRIGGER";
- else
- tag = "ALTER TABLE";
+ switch (((RenameStmt *) parsetree)->renameType)
+ {
+ case OBJECT_AGGREGATE:
+ tag = "ALTER AGGREGATE";
+ break;
+ case OBJECT_CONVERSION:
+ tag = "ALTER CONVERSION";
+ break;
+ case OBJECT_DATABASE:
+ tag = "ALTER DATABASE";
+ break;
+ case OBJECT_FUNCTION:
+ tag = "ALTER FUNCTION";
+ break;
+ case OBJECT_GROUP:
+ tag = "ALTER GROUP";
+ break;
+ case OBJECT_LANGUAGE:
+ tag = "ALTER LANGUAGE";
+ break;
+ case OBJECT_OPCLASS:
+ tag = "ALTER OPERATOR CLASS";
+ break;
+ case OBJECT_SCHEMA:
+ tag = "ALTER SCHEMA";
+ break;
+ case OBJECT_TRIGGER:
+ tag = "ALTER TRIGGER";
+ break;
+ case OBJECT_USER:
+ tag = "ALTER USER";
+ break;
+ default:
+ tag = "ALTER TABLE";
+ }
break;
case T_AlterTableStmt:
case T_DefineStmt:
switch (((DefineStmt *) parsetree)->kind)
{
- case DEFINE_STMT_AGGREGATE:
+ case OBJECT_AGGREGATE:
tag = "CREATE AGGREGATE";
break;
- case DEFINE_STMT_OPERATOR:
+ case OBJECT_OPERATOR:
tag = "CREATE OPERATOR";
break;
- case DEFINE_STMT_TYPE:
+ case OBJECT_TYPE:
tag = "CREATE TYPE";
break;
default:
case T_DropPropertyStmt:
switch (((DropPropertyStmt *) parsetree)->removeType)
{
- case DROP_TRIGGER:
+ case OBJECT_TRIGGER:
tag = "DROP TRIGGER";
break;
- case DROP_RULE:
+ case OBJECT_RULE:
tag = "DROP RULE";
break;
default:
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.28 2003/02/13 05:24:02 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/misc.c,v 1.29 2003/06/27 14:45:30 petere Exp $
*
*-------------------------------------------------------------------------
*/
db = (Name) palloc(NAMEDATALEN);
- namestrcpy(db, DatabaseName);
-
+ namestrcpy(db, get_database_name(MyDatabaseId));
PG_RETURN_NAME(db);
}
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.71 2003/05/28 18:19:09 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/globals.c,v 1.72 2003/06/27 14:45:30 petere Exp $
*
* NOTES
* Globals used all over the place should be declared here and not
BackendId MyBackendId;
-char *DatabaseName = NULL;
char *DatabasePath = NULL;
-
Oid MyDatabaseId = InvalidOid;
/* these are initialized for the bootstrap/standalone case: */
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.102 2003/04/04 20:42:12 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.103 2003/06/27 14:45:30 petere Exp $
*
*-------------------------------------------------------------------------
*/
}
}
-void
-SetDatabaseName(const char *name)
-{
- if (DatabaseName)
- {
- free(DatabaseName);
- DatabaseName = NULL;
- }
- /* use strdup since this is done before memory contexts are set up */
- if (name)
- {
- DatabaseName = strdup(name);
- AssertState(DatabaseName);
- }
-}
-
/*
* Set data directory, but make sure it's an absolute path. Use this,
* never set DataDir directly.
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.121 2003/05/14 03:26:02 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/init/postinit.c,v 1.122 2003/06/27 14:45:30 petere Exp $
*
*
*-------------------------------------------------------------------------
bool bootstrap = IsBootstrapProcessingMode();
/*
- * Set up the global variables holding database name, id, and path.
+ * Set up the global variables holding database id and path.
*
* We take a shortcut in the bootstrap case, otherwise we have to look up
* the db name in pg_database.
*/
- SetDatabaseName(dbname);
-
if (bootstrap)
{
MyDatabaseId = TemplateDbOid;
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.25 2002/12/05 04:04:47 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/misc/superuser.c,v 1.26 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
}
return result;
}
-
-
-/*
- * The Postgres user running this command is the owner of the specified
- * database.
- */
-bool
-is_dbadmin(Oid dbid)
-{
- AclId dba;
-
- dba = get_database_owner(dbid);
-
- return (GetUserId() == dba);
-}
--- /dev/null
+/*-------------------------------------------------------------------------
+ *
+ * alter.h
+ * prototypes for alter.h
+ *
+ *
+ * Portions Copyright (c) 1996-2003, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * $Id: alter.h,v 1.1 2003/06/27 14:45:31 petere Exp $
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef ALTER_H
+#define ALTER_H
+
+#include "nodes/parsenodes.h"
+
+extern void ExecRenameStmt(RenameStmt *stmt);
+
+#endif /* ALTER_H */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: conversioncmds.h,v 1.3 2002/09/04 20:31:42 momjian Exp $
+ * $Id: conversioncmds.h,v 1.4 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
extern void CreateConversionCommand(CreateConversionStmt *parsetree);
extern void DropConversionCommand(List *conversion_name, DropBehavior behavior);
+extern void RenameConversion(List *name, const char *newname);
#endif /* CONVERSIONCMDS_H */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: dbcommands.h,v 1.26 2002/09/05 00:43:07 tgl Exp $
+ * $Id: dbcommands.h,v 1.27 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
extern void createdb(const CreatedbStmt *stmt);
extern void dropdb(const char *dbname);
+extern void RenameDatabase(const char *oldname, const char *newname);
extern void AlterDatabaseSet(AlterDatabaseSetStmt *stmt);
-extern Oid get_database_oid(const char *dbname);
-extern Oid get_database_owner(Oid dbid);
+extern Oid get_database_oid(const char *dbname);
+extern char * get_database_name(Oid dbid);
#endif /* DBCOMMANDS_H */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: defrem.h,v 1.50 2002/12/10 16:12:52 tgl Exp $
+ * $Id: defrem.h,v 1.51 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
extern void RemoveFunctionById(Oid funcOid);
extern void SetFunctionReturnType(Oid funcOid, Oid newRetType);
extern void SetFunctionArgType(Oid funcOid, int argIndex, Oid newArgType);
+extern void RenameFunction(List *name, List *argtypes, const char *newname);
extern void CreateCast(CreateCastStmt *stmt);
extern void DropCast(DropCastStmt *stmt);
extern void DropCastById(Oid castOid);
/* commands/aggregatecmds.c */
extern void DefineAggregate(List *names, List *parameters);
extern void RemoveAggregate(RemoveAggrStmt *stmt);
+extern void RenameAggregate(List *name, TypeName *basetype, const char *newname);
/* commands/opclasscmds.c */
extern void DefineOpClass(CreateOpClassStmt *stmt);
extern void RemoveOpClass(RemoveOpClassStmt *stmt);
extern void RemoveOpClassById(Oid opclassOid);
-
+extern void RenameOpClass(List *name, const char *access_method, const char *newname);
/* support routines in commands/define.c */
extern void CreateProceduralLanguage(CreatePLangStmt *stmt);
extern void DropProceduralLanguage(DropPLangStmt *stmt);
extern void DropProceduralLanguageById(Oid langOid);
+extern void RenameLanguage(const char *oldname, const char *newname);
#endif /* PROCLANG_H */
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: schemacmds.h,v 1.3 2002/09/04 20:31:42 momjian Exp $
+ * $Id: schemacmds.h,v 1.4 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
extern void RemoveSchema(List *names, DropBehavior behavior);
extern void RemoveSchemaById(Oid schemaOid);
+extern void RenameSchema(const char *oldname, const char *newname);
+
#endif /* SCHEMACMDS_H */
* Commands for manipulating users and groups.
*
*
- * $Id: user.h,v 1.20 2002/10/21 19:46:45 tgl Exp $
+ * $Id: user.h,v 1.21 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
extern void AlterUser(AlterUserStmt *stmt);
extern void AlterUserSet(AlterUserSetStmt *stmt);
extern void DropUser(DropUserStmt *stmt);
+extern void RenameUser(const char *oldname, const char *newname);
extern void CreateGroup(CreateGroupStmt *stmt);
extern void AlterGroup(AlterGroupStmt *stmt, const char *tag);
extern void DropGroup(DropGroupStmt *stmt);
+extern void RenameGroup(const char *oldname, const char *newname);
extern Datum update_pg_pwd_and_pg_group(PG_FUNCTION_ARGS);
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: miscadmin.h,v 1.123 2003/05/28 18:19:09 tgl Exp $
+ * $Id: miscadmin.h,v 1.124 2003/06/27 14:45:31 petere Exp $
*
* NOTES
* some of the information in this file should be moved to
* POSTGRES directory path definitions. *
*****************************************************************************/
-extern char *DatabaseName;
extern char *DatabasePath;
/* in utils/misc/database.c */
extern char *ExpandDatabasePath(const char *path);
/* now in utils/init/miscinit.c */
-extern void SetDatabaseName(const char *name);
extern void SetDatabasePath(const char *path);
extern char *GetUserNameFromId(AclId userid);
/* in utils/misc/superuser.c */
extern bool superuser(void); /* current user is superuser */
extern bool superuser_arg(AclId userid); /* given user is superuser */
-extern bool is_dbadmin(Oid dbid); /* current user is owner of
- * database */
/*****************************************************************************
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: parsenodes.h,v 1.240 2003/06/25 04:19:24 momjian Exp $
+ * $Id: parsenodes.h,v 1.241 2003/06/27 14:45:31 petere Exp $
*
*-------------------------------------------------------------------------
*/
* field in Query.
*****************************************************************************/
+/*
+ * When a command can act on several kinds of objects with only one
+ * parse structure required, use these constants to designate the
+ * object type.
+ */
+
+typedef enum ObjectType {
+ OBJECT_AGGREGATE,
+ OBJECT_CAST,
+ OBJECT_COLUMN,
+ OBJECT_CONSTRAINT,
+ OBJECT_CONVERSION,
+ OBJECT_DATABASE,
+ OBJECT_DOMAIN,
+ OBJECT_FUNCTION,
+ OBJECT_GROUP,
+ OBJECT_INDEX,
+ OBJECT_LANGUAGE,
+ OBJECT_OPCLASS,
+ OBJECT_OPERATOR,
+ OBJECT_RULE,
+ OBJECT_SCHEMA,
+ OBJECT_SEQUENCE,
+ OBJECT_TABLE,
+ OBJECT_TRIGGER,
+ OBJECT_TYPE,
+ OBJECT_USER,
+ OBJECT_VIEW
+} ObjectType;
+
/* ----------------------
* Create Schema Statement
*
* Create {Aggregate|Operator|Type} Statement
* ----------------------
*/
-typedef enum DefineStmtKind
-{
- DEFINE_STMT_AGGREGATE,
- DEFINE_STMT_OPERATOR,
- DEFINE_STMT_TYPE
-} DefineStmtKind;
-
typedef struct DefineStmt
{
NodeTag type;
- DefineStmtKind kind; /* see above */
+ ObjectType kind; /* aggregate, operator, type */
List *defnames; /* qualified name (list of Value strings) */
List *definition; /* a list of DefElem */
} DefineStmt;
* ----------------------
*/
-#define DROP_TABLE 1
-#define DROP_SEQUENCE 2
-#define DROP_VIEW 3
-#define DROP_INDEX 4
-#define DROP_TYPE 5
-#define DROP_DOMAIN 6
-#define DROP_CONVERSION 7
-#define DROP_SCHEMA 8
-
typedef struct DropStmt
{
NodeTag type;
List *objects; /* list of sublists of names (as Values) */
- int removeType; /* see #defines above */
+ ObjectType removeType; /* object type */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropStmt;
* ----------------------
*/
-#define DROP_RULE 100
-#define DROP_TRIGGER 101
-
typedef struct DropPropertyStmt
{
NodeTag type;
RangeVar *relation; /* owning relation */
char *property; /* name of rule, trigger, etc */
- int removeType; /* see #defines above */
+ ObjectType removeType; /* OBJECT_RULE or OBJECT_TRIGGER */
DropBehavior behavior; /* RESTRICT or CASCADE behavior */
} DropPropertyStmt;
* Comment On Statement
* ----------------------
*/
-#define COMMENT_ON_AGGREGATE 100
-#define COMMENT_ON_COLUMN 101
-#define COMMENT_ON_CONSTRAINT 102
-#define COMMENT_ON_DATABASE 103
-#define COMMENT_ON_FUNCTION 104
-#define COMMENT_ON_INDEX 105
-#define COMMENT_ON_OPERATOR 106
-#define COMMENT_ON_RULE 107
-#define COMMENT_ON_SCHEMA 108
-#define COMMENT_ON_SEQUENCE 109
-#define COMMENT_ON_TABLE 110
-#define COMMENT_ON_TRIGGER 111
-#define COMMENT_ON_TYPE 112
-#define COMMENT_ON_VIEW 113
-
typedef struct CommentStmt
{
NodeTag type;
- int objtype; /* Object's type, see codes above */
+ ObjectType objtype; /* Object's type */
List *objname; /* Qualified name of the object */
List *objargs; /* Arguments if needed (eg, for functions) */
char *comment; /* Comment to insert, or NULL to remove */
/* ----------------------
* Alter Object Rename Statement
* ----------------------
- * Currently supports renaming tables, table columns, and triggers.
- * If renaming a table, oldname is ignored.
*/
-#define RENAME_TABLE 110
-#define RENAME_COLUMN 111
-#define RENAME_TRIGGER 112
-#define RENAME_RULE 113
-
typedef struct RenameStmt
{
NodeTag type;
- RangeVar *relation; /* owning relation */
- char *oldname; /* name of rule, trigger, etc */
+ RangeVar *relation; /* in case it's a table */
+ List *object; /* in case it's some other object */
+ List *objarg; /* argument types, if applicable */
+ char *subname; /* name of contained object (column, rule, trigger, etc) */
char *newname; /* the new name */
- int renameType; /* RENAME_TABLE, RENAME_COLUMN, etc */
+ ObjectType renameType; /* OBJECT_TABLE, OBJECT_COLUMN, etc */
} RenameStmt;
/* ----------------------
* REINDEX Statement
* ----------------------
*/
-typedef enum ReindexStmtKind
-{
- REINDEX_INDEX,
- REINDEX_TABLE,
- REINDEX_DATABASE
-} ReindexStmtKind;
-
typedef struct ReindexStmt
{
NodeTag type;
- ReindexStmtKind kind; /* see above */
+ ObjectType kind; /* OBJECT_INDEX, OBJECT_TABLE, OBJECT_DATABASE */
RangeVar *relation; /* Table or index to reindex */
const char *name; /* name of database to reindex */
bool force;
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California
*
- * $Id: acl.h,v 1.55 2003/06/27 00:33:26 tgl Exp $
+ * $Id: acl.h,v 1.56 2003/06/27 14:45:32 petere Exp $
*
* NOTES
* For backward-compatibility purposes we have to allow there
extern bool pg_proc_ownercheck(Oid proc_oid, AclId userid);
extern bool pg_namespace_ownercheck(Oid nsp_oid, AclId userid);
extern bool pg_opclass_ownercheck(Oid opc_oid, AclId userid);
+extern bool pg_database_ownercheck(Oid db_oid, AclId userid);
#endif /* ACL_H */