Commit d5e99ab4 authored by Tom Lane's avatar Tom Lane

pg_type has a typnamespace column; system now supports creating types

in different namespaces.  Also, cleanup work on relation namespace
support: drop, alter, rename commands work for tables in non-default
namespaces.
parent 7c1ff354
<!-- <!--
Documentation of the system catalogs, directed toward PostgreSQL developers Documentation of the system catalogs, directed toward PostgreSQL developers
$Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.38 2002/03/26 19:15:10 tgl Exp $ $Header: /cvsroot/pgsql/doc/src/sgml/catalogs.sgml,v 2.39 2002/03/29 19:05:57 tgl Exp $
--> -->
<chapter id="catalogs"> <chapter id="catalogs">
...@@ -2363,6 +2363,15 @@ ...@@ -2363,6 +2363,15 @@
<entry>Data type name</entry> <entry>Data type name</entry>
</row> </row>
<row>
<entry>typnamespace</entry>
<entry><type>oid</type></entry>
<entry>pg_namespace.oid</entry>
<entry>
The OID of the namespace that contains this type
</entry>
</row>
<row> <row>
<entry>typowner</entry> <entry>typowner</entry>
<entry><type>int4</type></entry> <entry><type>int4</type></entry>
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.77 2002/02/27 19:34:11 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/access/common/tupdesc.c,v 1.78 2002/03/29 19:05:59 tgl Exp $
* *
* NOTES * NOTES
* some of the executor utility code such as "ExecTypeFromTL" should be * some of the executor utility code such as "ExecTypeFromTL" should be
...@@ -322,7 +322,7 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2) ...@@ -322,7 +322,7 @@ equalTupleDescs(TupleDesc tupdesc1, TupleDesc tupdesc2)
* a preallocated tuple descriptor. * a preallocated tuple descriptor.
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
bool void
TupleDescInitEntry(TupleDesc desc, TupleDescInitEntry(TupleDesc desc,
AttrNumber attributeNumber, AttrNumber attributeNumber,
char *attributeName, char *attributeName,
...@@ -377,39 +377,11 @@ TupleDescInitEntry(TupleDesc desc, ...@@ -377,39 +377,11 @@ TupleDescInitEntry(TupleDesc desc,
att->attnotnull = false; att->attnotnull = false;
att->atthasdef = false; att->atthasdef = false;
/* ----------------
* search the system cache for the type tuple of the attribute
* we are creating so that we can get the typeid and some other
* stuff.
*
* Note: in the special case of
*
* create EMP (name = text, manager = EMP)
*
* RelationNameCreateHeapRelation() calls BuildDesc() which
* calls this routine and since EMP does not exist yet, the
* system cache lookup below fails. That's fine, but rather
* then doing a elog(ERROR) we just leave that information
* uninitialized, return false, then fix things up later.
* -cim 6/14/90
* ----------------
*/
tuple = SearchSysCache(TYPEOID, tuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(oidtypeid), ObjectIdGetDatum(oidtypeid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tuple)) if (!HeapTupleIsValid(tuple))
{ elog(ERROR, "Unable to look up type id %u", oidtypeid);
/*
* here type info does not exist yet so we just fill the attribute
* with dummy information and return false.
*/
att->atttypid = InvalidOid;
att->attlen = (int16) 0;
att->attbyval = (bool) 0;
att->attalign = 'i';
att->attstorage = 'p';
return false;
}
/* /*
* type info exists so we initialize our attribute information from * type info exists so we initialize our attribute information from
...@@ -477,56 +449,16 @@ TupleDescInitEntry(TupleDesc desc, ...@@ -477,56 +449,16 @@ TupleDescInitEntry(TupleDesc desc,
} }
ReleaseSysCache(tuple); ReleaseSysCache(tuple);
return true;
} }
/* ---------------------------------------------------------------- /*
* TupleDescMakeSelfReference * BuildDescForRelation
* *
* This function initializes a "self-referential" attribute like * Given a relation schema (list of ColumnDef nodes), build a TupleDesc.
* manager in "create EMP (name=text, manager = EMP)".
* It calls TypeShellMake() which inserts a "shell" type
* tuple into pg_type. A self-reference is one kind of set, so
* its size and byval are the same as for a set. See the comments
* above in TupleDescInitEntry.
* ----------------------------------------------------------------
*/
static void
TupleDescMakeSelfReference(TupleDesc desc,
AttrNumber attnum,
char *relname)
{
Form_pg_attribute att;
att = desc->attrs[attnum - 1];
att->atttypid = TypeShellMake(relname);
att->attlen = sizeof(Oid);
att->attbyval = true;
att->attalign = 'i';
att->attstorage = 'p';
att->attndims = 0;
}
/* ----------------------------------------------------------------
* BuildDescForRelation
*
* This is a general purpose function identical to BuildDesc
* but is used by the DefineRelation() code to catch the
* special case where you
*
* create FOO ( ..., x = FOO )
*
* here, the initial type lookup for "x = FOO" will fail
* because FOO isn't in the catalogs yet. But since we
* are creating FOO, instead of doing an elog() we add
* a shell type tuple to pg_type and fix things later
* in amcreate().
* ----------------------------------------------------------------
*/ */
TupleDesc TupleDesc
BuildDescForRelation(List *schema, char *relname) BuildDescForRelation(List *schema)
{ {
int natts; int natts;
AttrNumber attnum; AttrNumber attnum;
...@@ -535,7 +467,6 @@ BuildDescForRelation(List *schema, char *relname) ...@@ -535,7 +467,6 @@ BuildDescForRelation(List *schema, char *relname)
AttrDefault *attrdef = NULL; AttrDefault *attrdef = NULL;
TupleConstr *constr = (TupleConstr *) palloc(sizeof(TupleConstr)); TupleConstr *constr = (TupleConstr *) palloc(sizeof(TupleConstr));
char *attname; char *attname;
char typename[NAMEDATALEN];
int32 atttypmod; int32 atttypmod;
int attdim; int attdim;
int ndef = 0; int ndef = 0;
...@@ -553,7 +484,6 @@ BuildDescForRelation(List *schema, char *relname) ...@@ -553,7 +484,6 @@ BuildDescForRelation(List *schema, char *relname)
foreach(p, schema) foreach(p, schema)
{ {
ColumnDef *entry = lfirst(p); ColumnDef *entry = lfirst(p);
List *arry;
/* /*
* for each entry in the list, get the name and type information * for each entry in the list, get the name and type information
...@@ -563,39 +493,13 @@ BuildDescForRelation(List *schema, char *relname) ...@@ -563,39 +493,13 @@ BuildDescForRelation(List *schema, char *relname)
attnum++; attnum++;
attname = entry->colname; attname = entry->colname;
arry = entry->typename->arrayBounds;
attisset = entry->typename->setof; attisset = entry->typename->setof;
atttypmod = entry->typename->typmod; atttypmod = entry->typename->typmod;
attdim = length(entry->typename->arrayBounds);
if (arry != NIL) TupleDescInitEntry(desc, attnum, attname,
{ typenameTypeId(entry->typename),
/* array of XXX is _XXX */ atttypmod, attdim, attisset);
snprintf(typename, NAMEDATALEN,
"_%.*s", NAMEDATALEN - 2, entry->typename->name);
attdim = length(arry);
}
else
{
StrNCpy(typename, entry->typename->name, NAMEDATALEN);
attdim = 0;
}
if (!TupleDescInitEntry(desc, attnum, attname,
typenameTypeId(typename),
atttypmod, attdim, attisset))
{
/*
* if TupleDescInitEntry() fails, it means there is no type in
* the system catalogs. So now we check if the type name
* equals the relation name. If so we have a self reference,
* otherwise it's an error.
*/
if (strcmp(typename, relname) == 0)
TupleDescMakeSelfReference(desc, attnum, relname);
else
elog(ERROR, "DefineRelation: no such type %s",
typename);
}
/* This is for constraints */ /* This is for constraints */
if (entry->is_not_null) if (entry->is_not_null)
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.59 2002/03/26 19:15:22 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/aclchk.c,v 1.60 2002/03/29 19:05:59 tgl Exp $
* *
* NOTES * NOTES
* See acl.h. * See acl.h.
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "parser/parse_agg.h" #include "parser/parse_agg.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "parser/parse_expr.h" #include "parser/parse_expr.h"
#include "parser/parse_type.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/temprel.h" #include "utils/temprel.h"
...@@ -300,20 +301,19 @@ find_function_with_arglist(char *name, List *arguments) ...@@ -300,20 +301,19 @@ find_function_with_arglist(char *name, List *arguments)
for (i = 0; i < argcount; i++) for (i = 0; i < argcount; i++)
{ {
TypeName *t = (TypeName *) lfirst(arguments); TypeName *t = (TypeName *) lfirst(arguments);
char *typnam = TypeNameToInternalName(t);
arguments = lnext(arguments); argoids[i] = LookupTypeName(t);
if (!OidIsValid(argoids[i]))
if (strcmp(typnam, "opaque") == 0)
argoids[i] = InvalidOid;
else
{ {
argoids[i] = GetSysCacheOid(TYPENAME, char *typnam = TypeNameToString(t);
PointerGetDatum(typnam),
0, 0, 0); if (strcmp(typnam, "opaque") == 0)
if (!OidIsValid(argoids[i])) argoids[i] = InvalidOid;
elog(ERROR, "type '%s' not found", typnam); else
elog(ERROR, "Type \"%s\" does not exist", typnam);
} }
arguments = lnext(arguments);
} }
oid = GetSysCacheOid(PROCNAME, oid = GetSysCacheOid(PROCNAME,
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.192 2002/03/26 19:15:25 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/heap.c,v 1.193 2002/03/29 19:05:59 tgl Exp $
* *
* *
* INTERFACE ROUTINES * INTERFACE ROUTINES
...@@ -74,8 +74,10 @@ static void DeleteRelationTuple(Relation rel); ...@@ -74,8 +74,10 @@ static void DeleteRelationTuple(Relation rel);
static void DeleteTypeTuple(Relation rel); static void DeleteTypeTuple(Relation rel);
static void RelationRemoveIndexes(Relation relation); static void RelationRemoveIndexes(Relation relation);
static void RelationRemoveInheritance(Relation relation); static void RelationRemoveInheritance(Relation relation);
static void AddNewRelationType(char *typeName, Oid new_rel_oid, static void AddNewRelationType(const char *typeName,
Oid new_type_oid); Oid typeNamespace,
Oid new_rel_oid,
Oid new_type_oid);
static void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin); static void StoreAttrDefault(Relation rel, AttrNumber attnum, char *adbin);
static void StoreRelCheck(Relation rel, char *ccname, char *ccbin); static void StoreRelCheck(Relation rel, char *ccname, char *ccbin);
static void StoreConstraints(Relation rel, TupleDesc tupdesc); static void StoreConstraints(Relation rel, TupleDesc tupdesc);
...@@ -242,7 +244,7 @@ heap_create(char *relname, ...@@ -242,7 +244,7 @@ heap_create(char *relname,
* have to take special care for those rels that should be nailed * have to take special care for those rels that should be nailed
* in cache and/or are shared across databases. * in cache and/or are shared across databases.
*/ */
if (relname && relnamespace == PG_CATALOG_NAMESPACE) if (relnamespace == PG_CATALOG_NAMESPACE)
{ {
if (strcmp(TypeRelationName, relname) == 0) if (strcmp(TypeRelationName, relname) == 0)
{ {
...@@ -622,7 +624,10 @@ AddNewRelationTuple(Relation pg_class_desc, ...@@ -622,7 +624,10 @@ AddNewRelationTuple(Relation pg_class_desc,
* -------------------------------- * --------------------------------
*/ */
static void static void
AddNewRelationType(char *typeName, Oid new_rel_oid, Oid new_type_oid) AddNewRelationType(const char *typeName,
Oid typeNamespace,
Oid new_rel_oid,
Oid new_type_oid)
{ {
/* /*
* The sizes are set to oid size because it makes implementing sets * The sizes are set to oid size because it makes implementing sets
...@@ -634,18 +639,19 @@ AddNewRelationType(char *typeName, Oid new_rel_oid, Oid new_type_oid) ...@@ -634,18 +639,19 @@ AddNewRelationType(char *typeName, Oid new_rel_oid, Oid new_type_oid)
* true makes sets much easier, and it isn't used by anything else. * true makes sets much easier, and it isn't used by anything else.
*/ */
TypeCreate(typeName, /* type name */ TypeCreate(typeName, /* type name */
typeNamespace, /* type namespace */
new_type_oid, /* preassigned oid for type */ new_type_oid, /* preassigned oid for type */
new_rel_oid, /* relation oid */ new_rel_oid, /* relation oid */
sizeof(Oid), /* internal size */ sizeof(Oid), /* internal size */
-1, /* external size */ -1, /* external size */
'c', /* type-type (catalog) */ 'c', /* type-type (complex) */
',', /* default array delimiter */ ',', /* default array delimiter */
"oidin", /* input procedure */ F_OIDIN, /* input procedure */
"oidout", /* output procedure */ F_OIDOUT, /* output procedure */
"oidin", /* receive procedure */ F_OIDIN, /* receive procedure */
"oidout", /* send procedure */ F_OIDOUT, /* send procedure */
NULL, /* array element type - irrelevant */ InvalidOid, /* array element type - irrelevant */
NULL, /* baseType Name -- typically for domains */ InvalidOid, /* domain base type - irrelevant */
NULL, /* default type value - none */ NULL, /* default type value - none */
NULL, /* default type binary representation */ NULL, /* default type binary representation */
true, /* passed by value */ true, /* passed by value */
...@@ -744,7 +750,7 @@ heap_create_with_catalog(char *relname, ...@@ -744,7 +750,7 @@ heap_create_with_catalog(char *relname,
* NOTE: we could get a unique-index failure here, in case the same name * NOTE: we could get a unique-index failure here, in case the same name
* has already been used for a type. * has already been used for a type.
*/ */
AddNewRelationType(relname, new_rel_oid, new_type_oid); AddNewRelationType(relname, relnamespace, new_rel_oid, new_type_oid);
/* /*
* now add tuples to pg_attribute for the attributes in our new * now add tuples to pg_attribute for the attributes in our new
...@@ -1002,15 +1008,13 @@ RelationTruncateIndexes(Oid heapId) ...@@ -1002,15 +1008,13 @@ RelationTruncateIndexes(Oid heapId)
*/ */
void void
heap_truncate(const char *relname) heap_truncate(Oid rid)
{ {
Relation rel; Relation rel;
Oid rid;
/* Open relation for processing, and grab exclusive access on it. */ /* Open relation for processing, and grab exclusive access on it. */
rel = heap_openr(relname, AccessExclusiveLock); rel = heap_open(rid, AccessExclusiveLock);
rid = RelationGetRelid(rel);
/* /*
* TRUNCATE TABLE within a transaction block is dangerous, because if * TRUNCATE TABLE within a transaction block is dangerous, because if
...@@ -1217,21 +1221,22 @@ DeleteTypeTuple(Relation rel) ...@@ -1217,21 +1221,22 @@ DeleteTypeTuple(Relation rel)
* ---------------------------------------------------------------- * ----------------------------------------------------------------
*/ */
void void
heap_drop_with_catalog(const char *relname, heap_drop_with_catalog(Oid rid,
bool allow_system_table_mods) bool allow_system_table_mods)
{ {
Relation rel; Relation rel;
Oid rid; Oid toasttableOid;
bool has_toasttable; bool has_toasttable;
bool istemp = is_temp_rel_name(relname); bool istemp;
int i; int i;
/* /*
* Open and lock the relation. * Open and lock the relation.
*/ */
rel = heap_openr(relname, AccessExclusiveLock); rel = heap_open(rid, AccessExclusiveLock);
rid = RelationGetRelid(rel);
has_toasttable = rel->rd_rel->reltoastrelid != InvalidOid; has_toasttable = rel->rd_rel->reltoastrelid != InvalidOid;
toasttableOid = rel->rd_rel->reltoastrelid;
istemp = is_temp_rel_name(RelationGetRelationName(rel));
/* /*
* prevent deletion of system relations * prevent deletion of system relations
...@@ -1319,12 +1324,7 @@ heap_drop_with_catalog(const char *relname, ...@@ -1319,12 +1324,7 @@ heap_drop_with_catalog(const char *relname,
remove_temp_rel_by_relid(rid); remove_temp_rel_by_relid(rid);
if (has_toasttable) if (has_toasttable)
{ heap_drop_with_catalog(toasttableOid, true);
char toast_relname[NAMEDATALEN];
sprintf(toast_relname, "pg_toast_%u", rid);
heap_drop_with_catalog(toast_relname, true);
}
} }
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.85 2002/03/26 19:15:30 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/indexing.c,v 1.86 2002/03/29 19:06:00 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -76,7 +76,7 @@ char *Name_pg_statistic_indices[Num_pg_statistic_indices] = ...@@ -76,7 +76,7 @@ char *Name_pg_statistic_indices[Num_pg_statistic_indices] =
char *Name_pg_trigger_indices[Num_pg_trigger_indices] = char *Name_pg_trigger_indices[Num_pg_trigger_indices] =
{TriggerRelidIndex, TriggerConstrNameIndex, TriggerConstrRelidIndex, TriggerOidIndex}; {TriggerRelidIndex, TriggerConstrNameIndex, TriggerConstrRelidIndex, TriggerOidIndex};
char *Name_pg_type_indices[Num_pg_type_indices] = char *Name_pg_type_indices[Num_pg_type_indices] =
{TypeNameIndex, TypeOidIndex}; {TypeNameNspIndex, TypeOidIndex};
char *Name_pg_description_indices[Num_pg_description_indices] = char *Name_pg_description_indices[Num_pg_description_indices] =
{DescriptionObjIndex}; {DescriptionObjIndex};
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.1 2002/03/26 19:15:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/namespace.c,v 1.2 2002/03/29 19:06:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "catalog/namespace.h" #include "catalog/namespace.h"
#include "catalog/pg_namespace.h" #include "catalog/pg_namespace.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "utils/lsyscache.h" #include "utils/lsyscache.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -124,3 +125,92 @@ RelnameGetRelid(const char *relname) ...@@ -124,3 +125,92 @@ RelnameGetRelid(const char *relname)
/* XXX Wrong! must search search path */ /* XXX Wrong! must search search path */
return get_relname_relid(relname, PG_CATALOG_NAMESPACE); return get_relname_relid(relname, PG_CATALOG_NAMESPACE);
} }
/*
* QualifiedNameGetCreationNamespace
* Given a possibly-qualified name for an object (in List-of-Values
* format), determine what namespace the object should be created in.
* Also extract and return the object name (last component of list).
*/
Oid
QualifiedNameGetCreationNamespace(List *names, char **objname_p)
{
char *catalogname;
char *schemaname = NULL;
char *objname = NULL;
Oid namespaceId;
/* deconstruct the name list */
switch (length(names))
{
case 1:
objname = strVal(lfirst(names));
break;
case 2:
schemaname = strVal(lfirst(names));
objname = strVal(lsecond(names));
break;
case 3:
catalogname = strVal(lfirst(names));
schemaname = strVal(lsecond(names));
objname = strVal(lfirst(lnext(lnext(names))));
/*
* We check the catalog name and then ignore it.
*/
if (strcmp(catalogname, DatabaseName) != 0)
elog(ERROR, "Cross-database references are not implemented");
break;
default:
elog(ERROR, "Improper qualified name (too many dotted names)");
break;
}
if (schemaname)
{
namespaceId = GetSysCacheOid(NAMESPACENAME,
CStringGetDatum(schemaname),
0, 0, 0);
if (!OidIsValid(namespaceId))
elog(ERROR, "Namespace \"%s\" does not exist",
schemaname);
}
else
{
/* XXX Wrong! Need to get a default schema from somewhere */
namespaceId = PG_CATALOG_NAMESPACE;
}
*objname_p = objname;
return namespaceId;
}
/*
* makeRangeVarFromNameList
* Utility routine to convert a qualified-name list into RangeVar form.
*/
RangeVar *
makeRangeVarFromNameList(List *names)
{
RangeVar *rel = makeRangeVar(NULL, NULL);
switch (length(names))
{
case 1:
rel->relname = strVal(lfirst(names));
break;
case 2:
rel->schemaname = strVal(lfirst(names));
rel->relname = strVal(lsecond(names));
break;
case 3:
rel->catalogname = strVal(lfirst(names));
rel->schemaname = strVal(lsecond(names));
rel->relname = strVal(lfirst(lnext(lnext(names))));
break;
default:
elog(ERROR, "Improper relation name (too many dotted names)");
break;
}
return rel;
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.41 2002/03/20 19:43:35 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_aggregate.c,v 1.42 2002/03/29 19:06:01 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -23,34 +23,21 @@ ...@@ -23,34 +23,21 @@
#include "miscadmin.h" #include "miscadmin.h"
#include "parser/parse_coerce.h" #include "parser/parse_coerce.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "parser/parse_type.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/syscache.h" #include "utils/syscache.h"
/* ---------------- /*
* AggregateCreate * AggregateCreate
*
* aggregates overloading has been added. Instead of the full
* overload support we have for functions, aggregate overloading only
* applies to exact basetype matches. That is, we don't check the
* inheritance hierarchy
*
* OLD COMMENTS:
* Currently, redefining aggregates using the same name is not
* supported. In such a case, a warning is printed that the
* aggregate already exists. If such is not the case, a new tuple
* is created and inserted in the aggregate relation.
* All types and functions must have been defined
* prior to defining the aggregate.
*
* ---------------
*/ */
void void
AggregateCreate(char *aggName, AggregateCreate(const char *aggName,
Oid aggNamespace,
char *aggtransfnName, char *aggtransfnName,
char *aggfinalfnName, char *aggfinalfnName,
char *aggbasetypeName, Oid aggBaseType,
char *aggtranstypeName, Oid aggTransType,
char *agginitval) const char *agginitval)
{ {
Relation aggdesc; Relation aggdesc;
HeapTuple tup; HeapTuple tup;
...@@ -59,8 +46,6 @@ AggregateCreate(char *aggName, ...@@ -59,8 +46,6 @@ AggregateCreate(char *aggName,
Form_pg_proc proc; Form_pg_proc proc;
Oid transfn; Oid transfn;
Oid finalfn = InvalidOid; /* can be omitted */ Oid finalfn = InvalidOid; /* can be omitted */
Oid basetype;
Oid transtype;
Oid finaltype; Oid finaltype;
Oid fnArgs[FUNC_MAX_ARGS]; Oid fnArgs[FUNC_MAX_ARGS];
int nargs; int nargs;
...@@ -68,8 +53,6 @@ AggregateCreate(char *aggName, ...@@ -68,8 +53,6 @@ AggregateCreate(char *aggName,
TupleDesc tupDesc; TupleDesc tupDesc;
int i; int i;
MemSet(fnArgs, 0, FUNC_MAX_ARGS * sizeof(Oid));
/* sanity checks */ /* sanity checks */
if (!aggName) if (!aggName)
elog(ERROR, "no aggregate name supplied"); elog(ERROR, "no aggregate name supplied");
...@@ -77,44 +60,21 @@ AggregateCreate(char *aggName, ...@@ -77,44 +60,21 @@ AggregateCreate(char *aggName,
if (!aggtransfnName) if (!aggtransfnName)
elog(ERROR, "aggregate must have a transition function"); elog(ERROR, "aggregate must have a transition function");
/*
* Handle the aggregate's base type (input data type). This can be
* specified as 'ANY' for a data-independent transition function, such
* as COUNT(*).
*/
basetype = GetSysCacheOid(TYPENAME,
PointerGetDatum(aggbasetypeName),
0, 0, 0);
if (!OidIsValid(basetype))
{
if (strcasecmp(aggbasetypeName, "ANY") != 0)
elog(ERROR, "data type %s does not exist",
aggbasetypeName);
basetype = InvalidOid;
}
/* make sure there is no existing agg of same name and base type */ /* make sure there is no existing agg of same name and base type */
if (SearchSysCacheExists(AGGNAME, if (SearchSysCacheExists(AGGNAME,
PointerGetDatum(aggName), PointerGetDatum(aggName),
ObjectIdGetDatum(basetype), ObjectIdGetDatum(aggBaseType),
0, 0)) 0, 0))
elog(ERROR, elog(ERROR,
"aggregate function \"%s\" with base type %s already exists", "aggregate function \"%s\" with base type %s already exists",
aggName, aggbasetypeName); aggName, typeidTypeName(aggBaseType));
/* handle transtype */
transtype = GetSysCacheOid(TYPENAME,
PointerGetDatum(aggtranstypeName),
0, 0, 0);
if (!OidIsValid(transtype))
elog(ERROR, "data type %s does not exit",
aggtranstypeName);
/* handle transfn */ /* handle transfn */
fnArgs[0] = transtype; MemSet(fnArgs, 0, FUNC_MAX_ARGS * sizeof(Oid));
if (OidIsValid(basetype)) fnArgs[0] = aggTransType;
if (OidIsValid(aggBaseType))
{ {
fnArgs[1] = basetype; fnArgs[1] = aggBaseType;
nargs = 2; nargs = 2;
} }
else else
...@@ -129,9 +89,9 @@ AggregateCreate(char *aggName, ...@@ -129,9 +89,9 @@ AggregateCreate(char *aggName,
transfn = tup->t_data->t_oid; transfn = tup->t_data->t_oid;
Assert(OidIsValid(transfn)); Assert(OidIsValid(transfn));
proc = (Form_pg_proc) GETSTRUCT(tup); proc = (Form_pg_proc) GETSTRUCT(tup);
if (proc->prorettype != transtype) if (proc->prorettype != aggTransType)
elog(ERROR, "return type of transition function %s is not %s", elog(ERROR, "return type of transition function %s is not %s",
aggtransfnName, aggtranstypeName); aggtransfnName, typeidTypeName(aggTransType));
/* /*
* If the transfn is strict and the initval is NULL, make sure input * If the transfn is strict and the initval is NULL, make sure input
...@@ -141,7 +101,7 @@ AggregateCreate(char *aggName, ...@@ -141,7 +101,7 @@ AggregateCreate(char *aggName,
*/ */
if (proc->proisstrict && agginitval == NULL) if (proc->proisstrict && agginitval == NULL)
{ {
if (!IsBinaryCompatible(basetype, transtype)) if (!IsBinaryCompatible(aggBaseType, aggTransType))
elog(ERROR, "must not omit initval when transfn is strict and transtype is not compatible with input type"); elog(ERROR, "must not omit initval when transfn is strict and transtype is not compatible with input type");
} }
ReleaseSysCache(tup); ReleaseSysCache(tup);
...@@ -149,7 +109,7 @@ AggregateCreate(char *aggName, ...@@ -149,7 +109,7 @@ AggregateCreate(char *aggName,
/* handle finalfn, if supplied */ /* handle finalfn, if supplied */
if (aggfinalfnName) if (aggfinalfnName)
{ {
fnArgs[0] = transtype; fnArgs[0] = aggTransType;
fnArgs[1] = 0; fnArgs[1] = 0;
tup = SearchSysCache(PROCNAME, tup = SearchSysCache(PROCNAME,
PointerGetDatum(aggfinalfnName), PointerGetDatum(aggfinalfnName),
...@@ -169,7 +129,7 @@ AggregateCreate(char *aggName, ...@@ -169,7 +129,7 @@ AggregateCreate(char *aggName,
/* /*
* If no finalfn, aggregate result type is type of the state value * If no finalfn, aggregate result type is type of the state value
*/ */
finaltype = transtype; finaltype = aggTransType;
} }
Assert(OidIsValid(finaltype)); Assert(OidIsValid(finaltype));
...@@ -184,8 +144,8 @@ AggregateCreate(char *aggName, ...@@ -184,8 +144,8 @@ AggregateCreate(char *aggName,
values[Anum_pg_aggregate_aggowner - 1] = Int32GetDatum(GetUserId()); values[Anum_pg_aggregate_aggowner - 1] = Int32GetDatum(GetUserId());
values[Anum_pg_aggregate_aggtransfn - 1] = ObjectIdGetDatum(transfn); values[Anum_pg_aggregate_aggtransfn - 1] = ObjectIdGetDatum(transfn);
values[Anum_pg_aggregate_aggfinalfn - 1] = ObjectIdGetDatum(finalfn); values[Anum_pg_aggregate_aggfinalfn - 1] = ObjectIdGetDatum(finalfn);
values[Anum_pg_aggregate_aggbasetype - 1] = ObjectIdGetDatum(basetype); values[Anum_pg_aggregate_aggbasetype - 1] = ObjectIdGetDatum(aggBaseType);
values[Anum_pg_aggregate_aggtranstype - 1] = ObjectIdGetDatum(transtype); values[Anum_pg_aggregate_aggtranstype - 1] = ObjectIdGetDatum(aggTransType);
values[Anum_pg_aggregate_aggfinaltype - 1] = ObjectIdGetDatum(finaltype); values[Anum_pg_aggregate_aggfinaltype - 1] = ObjectIdGetDatum(finaltype);
if (agginitval) if (agginitval)
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.66 2002/03/20 19:43:36 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/catalog/pg_proc.c,v 1.67 2002/03/29 19:06:02 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -41,9 +41,10 @@ static void checkretval(Oid rettype, List *queryTreeList); ...@@ -41,9 +41,10 @@ static void checkretval(Oid rettype, List *queryTreeList);
*/ */
Oid Oid
ProcedureCreate(char *procedureName, ProcedureCreate(char *procedureName,
Oid procNamespace,
bool replace, bool replace,
bool returnsSet, bool returnsSet,
char *returnTypeName, Oid returnType,
Oid languageObjectId, Oid languageObjectId,
char *prosrc, char *prosrc,
char *probin, char *probin,
...@@ -60,17 +61,14 @@ ProcedureCreate(char *procedureName, ...@@ -60,17 +61,14 @@ ProcedureCreate(char *procedureName,
Relation rel; Relation rel;
HeapTuple tup; HeapTuple tup;
HeapTuple oldtup; HeapTuple oldtup;
bool defined;
uint16 parameterCount; uint16 parameterCount;
char nulls[Natts_pg_proc]; char nulls[Natts_pg_proc];
Datum values[Natts_pg_proc]; Datum values[Natts_pg_proc];
char replaces[Natts_pg_proc]; char replaces[Natts_pg_proc];
Oid typeObjectId;
List *x; List *x;
List *querytree_list; List *querytree_list;
Oid typev[FUNC_MAX_ARGS]; Oid typev[FUNC_MAX_ARGS];
Oid relid; Oid relid;
Oid toid;
NameData procname; NameData procname;
TupleDesc tupDesc; TupleDesc tupDesc;
Oid retval; Oid retval;
...@@ -86,28 +84,31 @@ ProcedureCreate(char *procedureName, ...@@ -86,28 +84,31 @@ ProcedureCreate(char *procedureName,
foreach(x, argList) foreach(x, argList)
{ {
TypeName *t = (TypeName *) lfirst(x); TypeName *t = (TypeName *) lfirst(x);
char *typnam = TypeNameToInternalName(t); Oid toid;
if (parameterCount >= FUNC_MAX_ARGS) if (parameterCount >= FUNC_MAX_ARGS)
elog(ERROR, "functions cannot have more than %d arguments", elog(ERROR, "functions cannot have more than %d arguments",
FUNC_MAX_ARGS); FUNC_MAX_ARGS);
if (strcmp(typnam, "opaque") == 0) toid = LookupTypeName(t);
if (OidIsValid(toid))
{ {
if (languageObjectId == SQLlanguageId) if (!get_typisdefined(toid))
elog(ERROR, "SQL functions cannot have arguments of type \"opaque\""); elog(WARNING, "Argument type \"%s\" is only a shell",
toid = InvalidOid; TypeNameToString(t));
} }
else else
{ {
toid = TypeGet(typnam, &defined); char *typnam = TypeNameToString(t);
if (!OidIsValid(toid)) if (strcmp(typnam, "opaque") == 0)
elog(ERROR, "argument type %s does not exist", {
typnam); if (languageObjectId == SQLlanguageId)
if (!defined) elog(ERROR, "SQL functions cannot have arguments of type \"opaque\"");
elog(WARNING, "argument type %s is only a shell", toid = InvalidOid;
typnam); }
else
elog(ERROR, "Type \"%s\" does not exist", typnam);
} }
if (t->setof) if (t->setof)
...@@ -154,41 +155,21 @@ ProcedureCreate(char *procedureName, ...@@ -154,41 +155,21 @@ ProcedureCreate(char *procedureName,
} }
} }
if (strcmp(returnTypeName, "opaque") == 0) if (!OidIsValid(returnType))
{ {
if (languageObjectId == SQLlanguageId) if (languageObjectId == SQLlanguageId)
elog(ERROR, "SQL functions cannot return type \"opaque\""); elog(ERROR, "SQL functions cannot return type \"opaque\"");
typeObjectId = InvalidOid;
}
else
{
typeObjectId = TypeGet(returnTypeName, &defined);
if (!OidIsValid(typeObjectId))
{
elog(WARNING, "ProcedureCreate: type %s is not yet defined",
returnTypeName);
typeObjectId = TypeShellMake(returnTypeName);
if (!OidIsValid(typeObjectId))
elog(ERROR, "could not create type %s",
returnTypeName);
}
else if (!defined)
elog(WARNING, "return type %s is only a shell",
returnTypeName);
} }
/* /*
* don't allow functions of complex types that have the same name as * don't allow functions of complex types that have the same name as
* existing attributes of the type * existing attributes of the type
*/ */
if (parameterCount == 1 && if (parameterCount == 1 && OidIsValid(typev[0]) &&
(toid = TypeGet(strVal(lfirst(argList)), &defined)) && (relid = typeidTypeRelid(typev[0])) != 0 &&
defined &&
(relid = typeidTypeRelid(toid)) != 0 &&
get_attnum(relid, procedureName) != InvalidAttrNumber) get_attnum(relid, procedureName) != InvalidAttrNumber)
elog(ERROR, "method %s already an attribute of type %s", elog(ERROR, "method %s already an attribute of type %s",
procedureName, strVal(lfirst(argList))); procedureName, typeidTypeName(typev[0]));
/* /*
* If this is a postquel procedure, we parse it here in order to be * If this is a postquel procedure, we parse it here in order to be
...@@ -201,7 +182,7 @@ ProcedureCreate(char *procedureName, ...@@ -201,7 +182,7 @@ ProcedureCreate(char *procedureName,
{ {
querytree_list = pg_parse_and_rewrite(prosrc, typev, parameterCount); querytree_list = pg_parse_and_rewrite(prosrc, typev, parameterCount);
/* typecheck return value */ /* typecheck return value */
checkretval(typeObjectId, querytree_list); checkretval(returnType, querytree_list);
} }
/* /*
...@@ -271,7 +252,7 @@ ProcedureCreate(char *procedureName, ...@@ -271,7 +252,7 @@ ProcedureCreate(char *procedureName,
values[i++] = BoolGetDatum(isStrict); values[i++] = BoolGetDatum(isStrict);
values[i++] = UInt16GetDatum(parameterCount); values[i++] = UInt16GetDatum(parameterCount);
values[i++] = BoolGetDatum(returnsSet); values[i++] = BoolGetDatum(returnsSet);
values[i++] = ObjectIdGetDatum(typeObjectId); values[i++] = ObjectIdGetDatum(returnType);
values[i++] = PointerGetDatum(typev); values[i++] = PointerGetDatum(typev);
values[i++] = Int32GetDatum(byte_pct); /* probyte_pct */ values[i++] = Int32GetDatum(byte_pct); /* probyte_pct */
values[i++] = Int32GetDatum(perbyte_cpu); /* properbyte_cpu */ values[i++] = Int32GetDatum(perbyte_cpu); /* properbyte_cpu */
...@@ -308,7 +289,7 @@ ProcedureCreate(char *procedureName, ...@@ -308,7 +289,7 @@ ProcedureCreate(char *procedureName,
* Not okay to change the return type of the existing proc, since * Not okay to change the return type of the existing proc, since
* existing rules, views, etc may depend on the return type. * existing rules, views, etc may depend on the return type.
*/ */
if (typeObjectId != oldproc->prorettype || if (returnType != oldproc->prorettype ||
returnsSet != oldproc->proretset) returnsSet != oldproc->proretset)
elog(ERROR, "ProcedureCreate: cannot change return type of existing function." elog(ERROR, "ProcedureCreate: cannot change return type of existing function."
"\n\tUse DROP FUNCTION first."); "\n\tUse DROP FUNCTION first.");
......
This diff is collapsed.
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.73 2002/03/26 19:15:35 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/cluster.c,v 1.74 2002/03/29 19:06:03 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -129,7 +129,7 @@ cluster(RangeVar *oldrelation, char *oldindexname) ...@@ -129,7 +129,7 @@ cluster(RangeVar *oldrelation, char *oldindexname)
CommandCounterIncrement(); CommandCounterIncrement();
/* Destroy old heap (along with its index) and rename new. */ /* Destroy old heap (along with its index) and rename new. */
heap_drop_with_catalog(saveoldrelation->relname, allowSystemTableMods); heap_drop_with_catalog(OIDOldHeap, allowSystemTableMods);
CommandCounterIncrement(); CommandCounterIncrement();
......
This diff is collapsed.
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* Copyright (c) 1999-2001, PostgreSQL Global Development Group * Copyright (c) 1999-2001, PostgreSQL Global Development Group
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.37 2002/03/26 19:15:38 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/comment.c,v 1.38 2002/03/29 19:06:04 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -27,9 +27,10 @@ ...@@ -27,9 +27,10 @@
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
#include "commands/comment.h" #include "commands/comment.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "nodes/makefuncs.h"
#include "parser/parse_agg.h" #include "parser/parse_agg.h"
#include "parser/parse_expr.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "parser/parse_type.h"
#include "parser/parse.h" #include "parser/parse.h"
#include "rewrite/rewriteRemove.h" #include "rewrite/rewriteRemove.h"
#include "utils/acl.h" #include "utils/acl.h"
...@@ -51,14 +52,16 @@ ...@@ -51,14 +52,16 @@
static void CommentRelation(int objtype, char * schemaname, char *relation, static void CommentRelation(int objtype, char * schemaname, char *relation,
char *comment); char *comment);
static void CommentAttribute(char *relation, char *attrib, char *comment); static void CommentAttribute(char * schemaname, char *relation,
char *attrib, char *comment);
static void CommentDatabase(char *database, char *comment); static void CommentDatabase(char *database, char *comment);
static void CommentRewrite(char *rule, char *comment); static void CommentRewrite(char *rule, char *comment);
static void CommentType(char *type, char *comment); static void CommentType(char *type, char *comment);
static void CommentAggregate(char *aggregate, List *arguments, char *comment); static void CommentAggregate(char *aggregate, List *arguments, char *comment);
static void CommentProc(char *function, List *arguments, char *comment); static void CommentProc(char *function, List *arguments, char *comment);
static void CommentOperator(char *opname, List *arguments, char *comment); static void CommentOperator(char *opname, List *arguments, char *comment);
static void CommentTrigger(char *trigger, char *relation, char *comments); static void CommentTrigger(char *trigger, char *schemaname, char *relation,
char *comments);
/*------------------------------------------------------------------ /*------------------------------------------------------------------
...@@ -88,7 +91,7 @@ CommentObject(int objtype, char *schemaname, char *objname, char *objproperty, ...@@ -88,7 +91,7 @@ CommentObject(int objtype, char *schemaname, char *objname, char *objproperty,
CommentRelation(objtype, schemaname, objname, comment); CommentRelation(objtype, schemaname, objname, comment);
break; break;
case COLUMN: case COLUMN:
CommentAttribute(objname, objproperty, comment); CommentAttribute(schemaname, objname, objproperty, comment);
break; break;
case DATABASE: case DATABASE:
CommentDatabase(objname, comment); CommentDatabase(objname, comment);
...@@ -109,7 +112,7 @@ CommentObject(int objtype, char *schemaname, char *objname, char *objproperty, ...@@ -109,7 +112,7 @@ CommentObject(int objtype, char *schemaname, char *objname, char *objproperty,
CommentOperator(objname, objlist, comment); CommentOperator(objname, objlist, comment);
break; break;
case TRIGGER: case TRIGGER:
CommentTrigger(objname, objproperty, comment); CommentTrigger(objname, schemaname, objproperty, comment);
break; break;
default: default:
elog(ERROR, "An attempt was made to comment on a unknown type: %d", elog(ERROR, "An attempt was made to comment on a unknown type: %d",
...@@ -391,14 +394,18 @@ CommentRelation(int reltype, char *schemaname, char *relname, char *comment) ...@@ -391,14 +394,18 @@ CommentRelation(int reltype, char *schemaname, char *relname, char *comment)
*/ */
static void static void
CommentAttribute(char *relname, char *attrname, char *comment) CommentAttribute(char *schemaname, char *relname, char *attrname, char *comment)
{ {
RangeVar *rel = makeNode(RangeVar);
Relation relation; Relation relation;
AttrNumber attnum; AttrNumber attnum;
/* Open the containing relation to ensure it won't go away meanwhile */ /* Open the containing relation to ensure it won't go away meanwhile */
relation = heap_openr(relname, AccessShareLock); rel->relname = relname;
rel->schemaname = schemaname;
rel->istemp = false;
relation = heap_openrv(rel, AccessShareLock);
/* Check object security */ /* Check object security */
...@@ -539,11 +546,8 @@ CommentType(char *type, char *comment) ...@@ -539,11 +546,8 @@ CommentType(char *type, char *comment)
/* Find the type's oid */ /* Find the type's oid */
oid = GetSysCacheOid(TYPENAME, /* XXX WRONG: need to deal with qualified type names */
PointerGetDatum(type), oid = typenameTypeId(makeTypeName(type));
0, 0, 0);
if (!OidIsValid(oid))
elog(ERROR, "type '%s' does not exist", type);
/* Check object security */ /* Check object security */
...@@ -570,21 +574,13 @@ static void ...@@ -570,21 +574,13 @@ static void
CommentAggregate(char *aggregate, List *arguments, char *comment) CommentAggregate(char *aggregate, List *arguments, char *comment)
{ {
TypeName *aggtype = (TypeName *) lfirst(arguments); TypeName *aggtype = (TypeName *) lfirst(arguments);
char *aggtypename;
Oid baseoid, Oid baseoid,
oid; oid;
Oid classoid; Oid classoid;
bool defined;
/* First, attempt to determine the base aggregate oid */ /* First, attempt to determine the base aggregate oid */
if (aggtype) if (aggtype)
{ baseoid = typenameTypeId(aggtype);
aggtypename = TypeNameToInternalName(aggtype);
baseoid = TypeGet(aggtypename, &defined);
if (!OidIsValid(baseoid))
elog(ERROR, "type '%s' does not exist", aggtypename);
}
else else
baseoid = InvalidOid; baseoid = InvalidOid;
...@@ -648,20 +644,19 @@ CommentProc(char *function, List *arguments, char *comment) ...@@ -648,20 +644,19 @@ CommentProc(char *function, List *arguments, char *comment)
for (i = 0; i < argcount; i++) for (i = 0; i < argcount; i++)
{ {
TypeName *t = (TypeName *) lfirst(arguments); TypeName *t = (TypeName *) lfirst(arguments);
char *typnam = TypeNameToInternalName(t);
arguments = lnext(arguments);
if (strcmp(typnam, "opaque") == 0) argoids[i] = LookupTypeName(t);
argoids[i] = InvalidOid; if (!OidIsValid(argoids[i]))
else
{ {
argoids[i] = GetSysCacheOid(TYPENAME, char *typnam = TypeNameToString(t);
PointerGetDatum(typnam),
0, 0, 0); if (strcmp(typnam, "opaque") == 0)
if (!OidIsValid(argoids[i])) argoids[i] = InvalidOid;
elog(ERROR, "CommentProc: type '%s' not found", typnam); else
elog(ERROR, "Type \"%s\" does not exist", typnam);
} }
arguments = lnext(arguments);
} }
/* Now, find the corresponding oid for this procedure */ /* Now, find the corresponding oid for this procedure */
...@@ -707,40 +702,20 @@ CommentOperator(char *opername, List *arguments, char *comment) ...@@ -707,40 +702,20 @@ CommentOperator(char *opername, List *arguments, char *comment)
{ {
TypeName *typenode1 = (TypeName *) lfirst(arguments); TypeName *typenode1 = (TypeName *) lfirst(arguments);
TypeName *typenode2 = (TypeName *) lsecond(arguments); TypeName *typenode2 = (TypeName *) lsecond(arguments);
char oprtype = 0, char oprtype = 0;
*lefttype = NULL,
*righttype = NULL;
Form_pg_operator data; Form_pg_operator data;
HeapTuple optuple; HeapTuple optuple;
Oid oid, Oid oid,
leftoid = InvalidOid, leftoid = InvalidOid,
rightoid = InvalidOid; rightoid = InvalidOid;
bool defined;
/* Initialize our left and right argument types */
/* Attempt to fetch the left type oid, if specified */
if (typenode1 != NULL) if (typenode1 != NULL)
lefttype = TypeNameToInternalName(typenode1); leftoid = typenameTypeId(typenode1);
if (typenode2 != NULL)
righttype = TypeNameToInternalName(typenode2);
/* Attempt to fetch the left oid, if specified */
if (lefttype != NULL)
{
leftoid = TypeGet(lefttype, &defined);
if (!OidIsValid(leftoid))
elog(ERROR, "left type '%s' does not exist", lefttype);
}
/* Attempt to fetch the right oid, if specified */
if (righttype != NULL) /* Attempt to fetch the right type oid, if specified */
{ if (typenode2 != NULL)
rightoid = TypeGet(righttype, &defined); rightoid = typenameTypeId(typenode2);
if (!OidIsValid(rightoid))
elog(ERROR, "right type '%s' does not exist", righttype);
}
/* Determine operator type */ /* Determine operator type */
...@@ -797,8 +772,9 @@ CommentOperator(char *opername, List *arguments, char *comment) ...@@ -797,8 +772,9 @@ CommentOperator(char *opername, List *arguments, char *comment)
*/ */
static void static void
CommentTrigger(char *trigger, char *relname, char *comment) CommentTrigger(char *trigger, char *schemaname, char *relname, char *comment)
{ {
RangeVar *rel = makeNode(RangeVar);
Relation pg_trigger, Relation pg_trigger,
relation; relation;
HeapTuple triggertuple; HeapTuple triggertuple;
...@@ -808,7 +784,10 @@ CommentTrigger(char *trigger, char *relname, char *comment) ...@@ -808,7 +784,10 @@ CommentTrigger(char *trigger, char *relname, char *comment)
/* First, validate the user's action */ /* First, validate the user's action */
relation = heap_openr(relname, AccessShareLock); rel->relname = relname;
rel->schemaname = schemaname;
rel->istemp = false;
relation = heap_openrv(rel, AccessShareLock);
if (!pg_class_ownercheck(RelationGetRelid(relation), GetUserId())) if (!pg_class_ownercheck(RelationGetRelid(relation), GetUserId()))
elog(ERROR, "you are not permitted to comment on trigger '%s' %s '%s'", elog(ERROR, "you are not permitted to comment on trigger '%s' %s '%s'",
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.151 2002/03/21 23:27:20 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/copy.c,v 1.152 2002/03/29 19:06:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "access/printtup.h" #include "access/printtup.h"
#include "catalog/catname.h" #include "catalog/catname.h"
#include "catalog/index.h" #include "catalog/index.h"
#include "catalog/namespace.h"
#include "catalog/pg_index.h" #include "catalog/pg_index.h"
#include "catalog/pg_shadow.h" #include "catalog/pg_shadow.h"
#include "catalog/pg_type.h" #include "catalog/pg_type.h"
...@@ -228,7 +229,7 @@ CopyDonePeek(FILE *fp, int c, bool pickup) ...@@ -228,7 +229,7 @@ CopyDonePeek(FILE *fp, int c, bool pickup)
/* /*
* DoCopy executes the SQL COPY statement. * DoCopy executes the SQL COPY statement.
* *
* Either unload or reload contents of table <relname>, depending on <from>. * Either unload or reload contents of table <relation>, depending on <from>.
* (<from> = TRUE means we are inserting into the table.) * (<from> = TRUE means we are inserting into the table.)
* *
* If <pipe> is false, transfer is between the table and the file named * If <pipe> is false, transfer is between the table and the file named
...@@ -260,7 +261,7 @@ CopyDonePeek(FILE *fp, int c, bool pickup) ...@@ -260,7 +261,7 @@ CopyDonePeek(FILE *fp, int c, bool pickup)
* the table. * the table.
*/ */
void void
DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, DoCopy(const RangeVar *relation, bool binary, bool oids, bool from, bool pipe,
char *filename, char *delim, char *null_print) char *filename, char *delim, char *null_print)
{ {
FILE *fp; FILE *fp;
...@@ -271,7 +272,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -271,7 +272,7 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
/* /*
* Open and lock the relation, using the appropriate lock type. * Open and lock the relation, using the appropriate lock type.
*/ */
rel = heap_openr(relname, (from ? RowExclusiveLock : AccessShareLock)); rel = heap_openrv(relation, (from ? RowExclusiveLock : AccessShareLock));
/* Check permissions. */ /* Check permissions. */
aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(), aclresult = pg_class_aclcheck(RelationGetRelid(rel), GetUserId(),
...@@ -312,11 +313,14 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -312,11 +313,14 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
if (rel->rd_rel->relkind != RELKIND_RELATION) if (rel->rd_rel->relkind != RELKIND_RELATION)
{ {
if (rel->rd_rel->relkind == RELKIND_VIEW) if (rel->rd_rel->relkind == RELKIND_VIEW)
elog(ERROR, "You cannot copy view %s", relname); elog(ERROR, "You cannot copy view %s",
RelationGetRelationName(rel));
else if (rel->rd_rel->relkind == RELKIND_SEQUENCE) else if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
elog(ERROR, "You cannot change sequence relation %s", relname); elog(ERROR, "You cannot change sequence relation %s",
RelationGetRelationName(rel));
else else
elog(ERROR, "You cannot copy object %s", relname); elog(ERROR, "You cannot copy object %s",
RelationGetRelationName(rel));
} }
if (pipe) if (pipe)
{ {
...@@ -354,11 +358,14 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe, ...@@ -354,11 +358,14 @@ DoCopy(char *relname, bool binary, bool oids, bool from, bool pipe,
if (rel->rd_rel->relkind != RELKIND_RELATION) if (rel->rd_rel->relkind != RELKIND_RELATION)
{ {
if (rel->rd_rel->relkind == RELKIND_VIEW) if (rel->rd_rel->relkind == RELKIND_VIEW)
elog(ERROR, "You cannot copy view %s", relname); elog(ERROR, "You cannot copy view %s",
RelationGetRelationName(rel));
else if (rel->rd_rel->relkind == RELKIND_SEQUENCE) else if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
elog(ERROR, "You cannot copy sequence %s", relname); elog(ERROR, "You cannot copy sequence %s",
RelationGetRelationName(rel));
else else
elog(ERROR, "You cannot copy object %s", relname); elog(ERROR, "You cannot copy object %s",
RelationGetRelationName(rel));
} }
if (pipe) if (pipe)
{ {
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.92 2002/03/26 19:15:40 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/creatinh.c,v 1.93 2002/03/29 19:06:05 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "commands/creatinh.h" #include "commands/creatinh.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "optimizer/clauses.h" #include "optimizer/clauses.h"
#include "parser/parse_type.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/syscache.h" #include "utils/syscache.h"
#include "utils/temprel.h" #include "utils/temprel.h"
...@@ -108,7 +109,7 @@ DefineRelation(CreateStmt *stmt, char relkind) ...@@ -108,7 +109,7 @@ DefineRelation(CreateStmt *stmt, char relkind)
* (BuildDescForRelation takes care of the inherited defaults, but we * (BuildDescForRelation takes care of the inherited defaults, but we
* have to copy inherited constraints here.) * have to copy inherited constraints here.)
*/ */
descriptor = BuildDescForRelation(schema, relname); descriptor = BuildDescForRelation(schema);
if (old_constraints != NIL) if (old_constraints != NIL)
{ {
...@@ -238,10 +239,12 @@ DefineRelation(CreateStmt *stmt, char relkind) ...@@ -238,10 +239,12 @@ DefineRelation(CreateStmt *stmt, char relkind)
* themselves will be destroyed, too. * themselves will be destroyed, too.
*/ */
void void
RemoveRelation(const char *name) RemoveRelation(const RangeVar *relation)
{ {
AssertArg(name); Oid relOid;
heap_drop_with_catalog(name, allowSystemTableMods);
relOid = RangeVarGetRelid(relation, false);
heap_drop_with_catalog(relOid, allowSystemTableMods);
} }
/* /*
...@@ -255,34 +258,36 @@ RemoveRelation(const char *name) ...@@ -255,34 +258,36 @@ RemoveRelation(const char *name)
* Rows are removed, indices are truncated and reconstructed. * Rows are removed, indices are truncated and reconstructed.
*/ */
void void
TruncateRelation(const char *relname) TruncateRelation(const RangeVar *relation)
{ {
Oid relid;
Relation rel; Relation rel;
AssertArg(relname); relid = RangeVarGetRelid(relation, false);
/* Grab exclusive lock in preparation for truncate */ /* Grab exclusive lock in preparation for truncate */
rel = heap_openr(relname, AccessExclusiveLock); rel = heap_open(relid, AccessExclusiveLock);
if (rel->rd_rel->relkind == RELKIND_SEQUENCE) if (rel->rd_rel->relkind == RELKIND_SEQUENCE)
elog(ERROR, "TRUNCATE cannot be used on sequences. '%s' is a sequence", elog(ERROR, "TRUNCATE cannot be used on sequences. '%s' is a sequence",
relname); RelationGetRelationName(rel));
if (rel->rd_rel->relkind == RELKIND_VIEW) if (rel->rd_rel->relkind == RELKIND_VIEW)
elog(ERROR, "TRUNCATE cannot be used on views. '%s' is a view", elog(ERROR, "TRUNCATE cannot be used on views. '%s' is a view",
relname); RelationGetRelationName(rel));
if (!allowSystemTableMods && IsSystemRelationName(relname)) if (!allowSystemTableMods && IsSystemRelationName(RelationGetRelationName(rel)))
elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table", elog(ERROR, "TRUNCATE cannot be used on system tables. '%s' is a system table",
relname); RelationGetRelationName(rel));
if (!pg_class_ownercheck(RelationGetRelid(rel), GetUserId())) if (!pg_class_ownercheck(RelationGetRelid(rel), GetUserId()))
elog(ERROR, "you do not own relation \"%s\"", relname); elog(ERROR, "you do not own relation \"%s\"",
RelationGetRelationName(rel));
/* Keep the lock until transaction commit */ /* Keep the lock until transaction commit */
heap_close(rel, NoLock); heap_close(rel, NoLock);
heap_truncate(relname); heap_truncate(relid);
} }
...@@ -308,12 +313,7 @@ MergeDomainAttributes(List *schema) ...@@ -308,12 +313,7 @@ MergeDomainAttributes(List *schema)
HeapTuple tuple; HeapTuple tuple;
Form_pg_type typeTup; Form_pg_type typeTup;
tuple = SearchSysCache(TYPENAME, tuple = typenameType(coldef->typename);
CStringGetDatum(coldef->typename->name),
0,0,0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "MergeDomainAttributes: Type %s does not exist",
coldef->typename->name);
typeTup = (Form_pg_type) GETSTRUCT(tuple); typeTup = (Form_pg_type) GETSTRUCT(tuple);
if (typeTup->typtype == 'd') if (typeTup->typtype == 'd')
...@@ -486,26 +486,11 @@ MergeAttributes(List *schema, List *supers, bool istemp, ...@@ -486,26 +486,11 @@ MergeAttributes(List *schema, List *supers, bool istemp,
parent_attno++) parent_attno++)
{ {
Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1]; Form_pg_attribute attribute = tupleDesc->attrs[parent_attno - 1];
char *attributeName; char *attributeName = NameStr(attribute->attname);
char *attributeType;
HeapTuple tuple;
int exist_attno; int exist_attno;
ColumnDef *def; ColumnDef *def;
TypeName *typename; TypeName *typename;
/*
* Get name and type name of attribute
*/
attributeName = NameStr(attribute->attname);
tuple = SearchSysCache(TYPEOID,
ObjectIdGetDatum(attribute->atttypid),
0, 0, 0);
if (!HeapTupleIsValid(tuple))
elog(ERROR, "CREATE TABLE: cache lookup failed for type %u",
attribute->atttypid);
attributeType = pstrdup(NameStr(((Form_pg_type) GETSTRUCT(tuple))->typname));
ReleaseSysCache(tuple);
/* /*
* Does it conflict with some previously inherited column? * Does it conflict with some previously inherited column?
*/ */
...@@ -519,10 +504,12 @@ MergeAttributes(List *schema, List *supers, bool istemp, ...@@ -519,10 +504,12 @@ MergeAttributes(List *schema, List *supers, bool istemp,
elog(NOTICE, "CREATE TABLE: merging multiple inherited definitions of attribute \"%s\"", elog(NOTICE, "CREATE TABLE: merging multiple inherited definitions of attribute \"%s\"",
attributeName); attributeName);
def = (ColumnDef *) nth(exist_attno - 1, inhSchema); def = (ColumnDef *) nth(exist_attno - 1, inhSchema);
if (strcmp(def->typename->name, attributeType) != 0 || if (typenameTypeId(def->typename) != attribute->atttypid ||
def->typename->typmod != attribute->atttypmod) def->typename->typmod != attribute->atttypmod)
elog(ERROR, "CREATE TABLE: inherited attribute \"%s\" type conflict (%s and %s)", elog(ERROR, "CREATE TABLE: inherited attribute \"%s\" type conflict (%s and %s)",
attributeName, def->typename->name, attributeType); attributeName,
TypeNameToString(def->typename),
typeidTypeName(attribute->atttypid));
/* Merge of NOT NULL constraints = OR 'em together */ /* Merge of NOT NULL constraints = OR 'em together */
def->is_not_null |= attribute->attnotnull; def->is_not_null |= attribute->attnotnull;
/* Default and other constraints are handled below */ /* Default and other constraints are handled below */
...@@ -536,7 +523,7 @@ MergeAttributes(List *schema, List *supers, bool istemp, ...@@ -536,7 +523,7 @@ MergeAttributes(List *schema, List *supers, bool istemp,
def = makeNode(ColumnDef); def = makeNode(ColumnDef);
def->colname = pstrdup(attributeName); def->colname = pstrdup(attributeName);
typename = makeNode(TypeName); typename = makeNode(TypeName);
typename->name = attributeType; typename->typeid = attribute->atttypid;
typename->typmod = attribute->atttypmod; typename->typmod = attribute->atttypmod;
def->typename = typename; def->typename = typename;
def->is_not_null = attribute->attnotnull; def->is_not_null = attribute->attnotnull;
...@@ -640,7 +627,6 @@ MergeAttributes(List *schema, List *supers, bool istemp, ...@@ -640,7 +627,6 @@ MergeAttributes(List *schema, List *supers, bool istemp,
{ {
ColumnDef *newdef = lfirst(entry); ColumnDef *newdef = lfirst(entry);
char *attributeName = newdef->colname; char *attributeName = newdef->colname;
char *attributeType = newdef->typename->name;
int exist_attno; int exist_attno;
/* /*
...@@ -658,10 +644,12 @@ MergeAttributes(List *schema, List *supers, bool istemp, ...@@ -658,10 +644,12 @@ MergeAttributes(List *schema, List *supers, bool istemp,
elog(NOTICE, "CREATE TABLE: merging attribute \"%s\" with inherited definition", elog(NOTICE, "CREATE TABLE: merging attribute \"%s\" with inherited definition",
attributeName); attributeName);
def = (ColumnDef *) nth(exist_attno - 1, inhSchema); def = (ColumnDef *) nth(exist_attno - 1, inhSchema);
if (strcmp(def->typename->name, attributeType) != 0 || if (typenameTypeId(def->typename) != typenameTypeId(newdef->typename) ||
def->typename->typmod != newdef->typename->typmod) def->typename->typmod != newdef->typename->typmod)
elog(ERROR, "CREATE TABLE: attribute \"%s\" type conflict (%s and %s)", elog(ERROR, "CREATE TABLE: attribute \"%s\" type conflict (%s and %s)",
attributeName, def->typename->name, attributeType); attributeName,
TypeNameToString(def->typename),
TypeNameToString(newdef->typename));
/* Merge of NOT NULL constraints = OR 'em together */ /* Merge of NOT NULL constraints = OR 'em together */
def->is_not_null |= newdef->is_not_null; def->is_not_null |= newdef->is_not_null;
/* If new def has a default, override previous default */ /* If new def has a default, override previous default */
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.71 2002/03/21 23:27:21 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/remove.c,v 1.72 2002/03/29 19:06:06 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -24,8 +24,8 @@ ...@@ -24,8 +24,8 @@
#include "miscadmin.h" #include "miscadmin.h"
#include "parser/parse.h" #include "parser/parse.h"
#include "parser/parse_agg.h" #include "parser/parse_agg.h"
#include "parser/parse_expr.h"
#include "parser/parse_func.h" #include "parser/parse_func.h"
#include "parser/parse_type.h"
#include "utils/acl.h" #include "utils/acl.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/syscache.h" #include "utils/syscache.h"
...@@ -43,29 +43,20 @@ ...@@ -43,29 +43,20 @@
*/ */
void void
RemoveOperator(char *operatorName, /* operator name */ RemoveOperator(char *operatorName, /* operator name */
char *typeName1, /* left argument type name */ TypeName *typeName1, /* left argument type name */
char *typeName2) /* right argument type name */ TypeName *typeName2) /* right argument type name */
{ {
Relation relation; Relation relation;
HeapTuple tup; HeapTuple tup;
Oid typeId1 = InvalidOid; Oid typeId1 = InvalidOid;
Oid typeId2 = InvalidOid; Oid typeId2 = InvalidOid;
bool defined;
char oprtype; char oprtype;
if (typeName1) if (typeName1)
{ typeId1 = typenameTypeId(typeName1);
typeId1 = TypeGet(typeName1, &defined);
if (!OidIsValid(typeId1))
elog(ERROR, "RemoveOperator: type '%s' does not exist", typeName1);
}
if (typeName2) if (typeName2)
{ typeId2 = typenameTypeId(typeName2);
typeId2 = TypeGet(typeName2, &defined);
if (!OidIsValid(typeId2))
elog(ERROR, "RemoveOperator: type '%s' does not exist", typeName2);
}
if (OidIsValid(typeId1) && OidIsValid(typeId2)) if (OidIsValid(typeId1) && OidIsValid(typeId2))
oprtype = 'b'; oprtype = 'b';
...@@ -99,20 +90,20 @@ RemoveOperator(char *operatorName, /* operator name */ ...@@ -99,20 +90,20 @@ RemoveOperator(char *operatorName, /* operator name */
{ {
elog(ERROR, "RemoveOperator: binary operator '%s' taking '%s' and '%s' does not exist", elog(ERROR, "RemoveOperator: binary operator '%s' taking '%s' and '%s' does not exist",
operatorName, operatorName,
typeName1, TypeNameToString(typeName1),
typeName2); TypeNameToString(typeName2));
} }
else if (OidIsValid(typeId1)) else if (OidIsValid(typeId1))
{ {
elog(ERROR, "RemoveOperator: right unary operator '%s' taking '%s' does not exist", elog(ERROR, "RemoveOperator: right unary operator '%s' taking '%s' does not exist",
operatorName, operatorName,
typeName1); TypeNameToString(typeName1));
} }
else else
{ {
elog(ERROR, "RemoveOperator: left unary operator '%s' taking '%s' does not exist", elog(ERROR, "RemoveOperator: left unary operator '%s' taking '%s' does not exist",
operatorName, operatorName,
typeName2); TypeNameToString(typeName2));
} }
} }
heap_freetuple(tup); heap_freetuple(tup);
...@@ -213,16 +204,13 @@ AttributeAndRelationRemove(Oid typeOid) ...@@ -213,16 +204,13 @@ AttributeAndRelationRemove(Oid typeOid)
rel = heap_openr(RelationRelationName, RowExclusiveLock); rel = heap_openr(RelationRelationName, RowExclusiveLock);
while (PointerIsValid((char *) optr->next)) while (PointerIsValid((char *) optr->next))
{ {
key[0].sk_argument = (Datum) (optr++)->reloid; Oid relOid = (optr++)->reloid;
key[0].sk_argument = ObjectIdGetDatum(relOid);
scan = heap_beginscan(rel, 0, SnapshotNow, 1, key); scan = heap_beginscan(rel, 0, SnapshotNow, 1, key);
tup = heap_getnext(scan, 0); tup = heap_getnext(scan, 0);
if (HeapTupleIsValid(tup)) if (HeapTupleIsValid(tup))
{ heap_drop_with_catalog(relOid, allowSystemTableMods);
char *name;
name = NameStr(((Form_pg_class) GETSTRUCT(tup))->relname);
heap_drop_with_catalog(name, allowSystemTableMods);
}
heap_endscan(scan); heap_endscan(scan);
} }
heap_close(rel, RowExclusiveLock); heap_close(rel, RowExclusiveLock);
...@@ -231,42 +219,68 @@ AttributeAndRelationRemove(Oid typeOid) ...@@ -231,42 +219,68 @@ AttributeAndRelationRemove(Oid typeOid)
/* /*
* TypeRemove * TypeRemove
* Removes the type 'typeName' and all attributes and relations that * Removes a datatype.
* use it. *
* NOTE: since this tries to remove the associated array type too, it'll
* only work on scalar types.
*/ */
void void
RemoveType(char *typeName) /* type name to be removed */ RemoveType(List *names)
{ {
TypeName *typename;
Relation relation; Relation relation;
Oid typeoid;
HeapTuple tup; HeapTuple tup;
char *shadow_type;
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeNode(TypeName);
typename->names = names;
typename->typmod = -1;
typename->arrayBounds = NIL;
relation = heap_openr(TypeRelationName, RowExclusiveLock); relation = heap_openr(TypeRelationName, RowExclusiveLock);
tup = SearchSysCache(TYPENAME, /* Use LookupTypeName here so that shell types can be removed. */
PointerGetDatum(typeName), typeoid = LookupTypeName(typename);
if (!OidIsValid(typeoid))
elog(ERROR, "Type \"%s\" does not exist",
TypeNameToString(typename));
tup = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typeoid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "RemoveType: type '%s' does not exist", typeName); elog(ERROR, "Type \"%s\" does not exist",
TypeNameToString(typename));
if (!pg_type_ownercheck(tup->t_data->t_oid, GetUserId())) if (!pg_type_ownercheck(typeoid, GetUserId()))
elog(ERROR, "RemoveType: type '%s': permission denied", elog(ERROR, "RemoveType: type '%s': permission denied",
typeName); TypeNameToString(typename));
/* Delete any comments associated with this type */ /* Delete any comments associated with this type */
DeleteComments(tup->t_data->t_oid, RelationGetRelid(relation)); DeleteComments(typeoid, RelationGetRelid(relation));
/* Remove the type tuple from pg_type */
simple_heap_delete(relation, &tup->t_self); simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup); ReleaseSysCache(tup);
/* Also, delete the "array of" that type */ /* Now, delete the "array of" that type */
shadow_type = makeArrayTypeName(typeName); typename->arrayBounds = makeList1(makeInteger(1));
tup = SearchSysCache(TYPENAME,
PointerGetDatum(shadow_type), typeoid = LookupTypeName(typename);
if (!OidIsValid(typeoid))
elog(ERROR, "Type \"%s\" does not exist",
TypeNameToString(typename));
tup = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typeoid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "RemoveType: type '%s' does not exist", shadow_type); elog(ERROR, "Type \"%s\" does not exist",
TypeNameToString(typename));
DeleteComments(typeoid, RelationGetRelid(relation));
simple_heap_delete(relation, &tup->t_self); simple_heap_delete(relation, &tup->t_self);
...@@ -277,13 +291,14 @@ RemoveType(char *typeName) /* type name to be removed */ ...@@ -277,13 +291,14 @@ RemoveType(char *typeName) /* type name to be removed */
/* /*
* RemoveDomain * RemoveDomain
* Removes the domain 'typeName' and all attributes and relations that * Removes a domain.
* use it.
*/ */
void void
RemoveDomain(char *domainName, int behavior) RemoveDomain(List *names, int behavior)
{ {
TypeName *typename;
Relation relation; Relation relation;
Oid typeoid;
HeapTuple tup; HeapTuple tup;
char typtype; char typtype;
...@@ -291,31 +306,44 @@ RemoveDomain(char *domainName, int behavior) ...@@ -291,31 +306,44 @@ RemoveDomain(char *domainName, int behavior)
if (behavior == CASCADE) if (behavior == CASCADE)
elog(ERROR, "DROP DOMAIN does not support the CASCADE keyword"); elog(ERROR, "DROP DOMAIN does not support the CASCADE keyword");
/* Make a TypeName so we can use standard type lookup machinery */
typename = makeNode(TypeName);
typename->names = names;
typename->typmod = -1;
typename->arrayBounds = NIL;
relation = heap_openr(TypeRelationName, RowExclusiveLock); relation = heap_openr(TypeRelationName, RowExclusiveLock);
tup = SearchSysCache(TYPENAME, typeoid = typenameTypeId(typename);
PointerGetDatum(domainName),
tup = SearchSysCache(TYPEOID,
ObjectIdGetDatum(typeoid),
0, 0, 0); 0, 0, 0);
if (!HeapTupleIsValid(tup)) if (!HeapTupleIsValid(tup))
elog(ERROR, "RemoveType: type '%s' does not exist", domainName); elog(ERROR, "RemoveDomain: type '%s' does not exist",
TypeNameToString(typename));
if (!pg_type_ownercheck(tup->t_data->t_oid, GetUserId())) if (!pg_type_ownercheck(typeoid, GetUserId()))
elog(ERROR, "RemoveDomain: type '%s': permission denied", elog(ERROR, "RemoveDomain: type '%s': permission denied",
domainName); TypeNameToString(typename));
/* Check that this is actually a domain */ /* Check that this is actually a domain */
typtype = ((Form_pg_type) GETSTRUCT(tup))->typtype; typtype = ((Form_pg_type) GETSTRUCT(tup))->typtype;
if (typtype != 'd') if (typtype != 'd')
elog(ERROR, "%s is not a domain", domainName); elog(ERROR, "%s is not a domain",
TypeNameToString(typename));
/* Delete any comments associated with this type */ /* Delete any comments associated with this type */
DeleteComments(tup->t_data->t_oid, RelationGetRelid(relation)); DeleteComments(typeoid, RelationGetRelid(relation));
/* Remove the type tuple from pg_type */
simple_heap_delete(relation, &tup->t_self); simple_heap_delete(relation, &tup->t_self);
ReleaseSysCache(tup); ReleaseSysCache(tup);
/* At present, domains don't have associated array types */
heap_close(relation, RowExclusiveLock); heap_close(relation, RowExclusiveLock);
} }
...@@ -345,20 +373,19 @@ RemoveFunction(char *functionName, /* function name to be removed */ ...@@ -345,20 +373,19 @@ RemoveFunction(char *functionName, /* function name to be removed */
for (i = 0; i < nargs; i++) for (i = 0; i < nargs; i++)
{ {
TypeName *t = (TypeName *) lfirst(argTypes); TypeName *t = (TypeName *) lfirst(argTypes);
char *typnam = TypeNameToInternalName(t);
argTypes = lnext(argTypes);
if (strcmp(typnam, "opaque") == 0) argList[i] = LookupTypeName(t);
argList[i] = InvalidOid; if (!OidIsValid(argList[i]))
else
{ {
argList[i] = GetSysCacheOid(TYPENAME, char *typnam = TypeNameToString(t);
PointerGetDatum(typnam),
0, 0, 0); if (strcmp(typnam, "opaque") == 0)
if (!OidIsValid(argList[i])) argList[i] = InvalidOid;
elog(ERROR, "RemoveFunction: type '%s' not found", typnam); else
elog(ERROR, "Type \"%s\" does not exist", typnam);
} }
argTypes = lnext(argTypes);
} }
relation = heap_openr(ProcedureRelationName, RowExclusiveLock); relation = heap_openr(ProcedureRelationName, RowExclusiveLock);
...@@ -393,12 +420,11 @@ RemoveFunction(char *functionName, /* function name to be removed */ ...@@ -393,12 +420,11 @@ RemoveFunction(char *functionName, /* function name to be removed */
} }
void void
RemoveAggregate(char *aggName, char *aggType) RemoveAggregate(char *aggName, TypeName *aggType)
{ {
Relation relation; Relation relation;
HeapTuple tup; HeapTuple tup;
Oid basetypeID; Oid basetypeID;
bool defined;
/* /*
* if a basetype is passed in, then attempt to find an aggregate for * if a basetype is passed in, then attempt to find an aggregate for
...@@ -410,11 +436,7 @@ RemoveAggregate(char *aggName, char *aggType) ...@@ -410,11 +436,7 @@ RemoveAggregate(char *aggName, char *aggType)
*/ */
if (aggType) if (aggType)
{ basetypeID = typenameTypeId(aggType);
basetypeID = TypeGet(aggType, &defined);
if (!OidIsValid(basetypeID))
elog(ERROR, "RemoveAggregate: type '%s' does not exist", aggType);
}
else else
basetypeID = InvalidOid; basetypeID = InvalidOid;
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.65 2002/03/26 19:15:43 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/Attic/rename.c,v 1.66 2002/03/29 19:06:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -69,16 +69,14 @@ static void update_ri_trigger_args(Oid relid, ...@@ -69,16 +69,14 @@ static void update_ri_trigger_args(Oid relid,
* delete original attribute from attribute catalog * delete original attribute from attribute catalog
*/ */
void void
renameatt(char *relname, renameatt(Oid relid,
char *oldattname, char *oldattname,
char *newattname, char *newattname,
int recurse) bool recurse)
{ {
Relation targetrelation; Relation targetrelation;
Relation attrelation; Relation attrelation;
HeapTuple reltup, HeapTuple atttup;
atttup;
Oid relid;
List *indexoidlist; List *indexoidlist;
List *indexoidscan; List *indexoidscan;
...@@ -86,8 +84,7 @@ renameatt(char *relname, ...@@ -86,8 +84,7 @@ renameatt(char *relname,
* Grab an exclusive lock on the target table, which we will NOT * Grab an exclusive lock on the target table, which we will NOT
* release until end of transaction. * release until end of transaction.
*/ */
targetrelation = heap_openr(relname, AccessExclusiveLock); targetrelation = heap_open(relid, AccessExclusiveLock);
relid = RelationGetRelid(targetrelation);
/* /*
* permissions checking. this would normally be done in utility.c, * permissions checking. this would normally be done in utility.c,
...@@ -95,12 +92,13 @@ renameatt(char *relname, ...@@ -95,12 +92,13 @@ renameatt(char *relname,
* *
* normally, only the owner of a class can change its schema. * normally, only the owner of a class can change its schema.
*/ */
if (!allowSystemTableMods && IsSystemRelationName(relname)) if (!allowSystemTableMods
&& IsSystemRelationName(RelationGetRelationName(targetrelation)))
elog(ERROR, "renameatt: class \"%s\" is a system catalog", elog(ERROR, "renameatt: class \"%s\" is a system catalog",
relname); RelationGetRelationName(targetrelation));
if (!pg_class_ownercheck(relid, GetUserId())) if (!pg_class_ownercheck(relid, GetUserId()))
elog(ERROR, "renameatt: you do not own class \"%s\"", elog(ERROR, "renameatt: you do not own class \"%s\"",
relname); RelationGetRelationName(targetrelation));
/* /*
* if the 'recurse' flag is set then we are supposed to rename this * if the 'recurse' flag is set then we are supposed to rename this
...@@ -127,25 +125,11 @@ renameatt(char *relname, ...@@ -127,25 +125,11 @@ renameatt(char *relname,
foreach(child, children) foreach(child, children)
{ {
Oid childrelid = lfirsti(child); Oid childrelid = lfirsti(child);
char childname[NAMEDATALEN];
if (childrelid == relid) if (childrelid == relid)
continue; continue;
reltup = SearchSysCache(RELOID,
ObjectIdGetDatum(childrelid),
0, 0, 0);
if (!HeapTupleIsValid(reltup))
{
elog(ERROR, "renameatt: can't find catalog entry for inheriting class with oid %u",
childrelid);
}
/* make copy of cache value, could disappear in call */
StrNCpy(childname,
NameStr(((Form_pg_class) GETSTRUCT(reltup))->relname),
NAMEDATALEN);
ReleaseSysCache(reltup);
/* note we need not recurse again! */ /* note we need not recurse again! */
renameatt(childname, oldattname, newattname, 0); renameatt(childrelid, oldattname, newattname, false);
} }
} }
...@@ -356,7 +340,7 @@ renamerel(const RangeVar *relation, const char *newrelname) ...@@ -356,7 +340,7 @@ renamerel(const RangeVar *relation, const char *newrelname)
* Also rename the associated type, if any. * Also rename the associated type, if any.
*/ */
if (relkind != RELKIND_INDEX) if (relkind != RELKIND_INDEX)
TypeRename(relation->relname, newrelname); TypeRename(relation->relname, namespaceId, newrelname);
/* /*
* If it's a view, must also rename the associated ON SELECT rule. * If it's a view, must also rename the associated ON SELECT rule.
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.74 2002/03/22 02:56:31 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/sequence.c,v 1.75 2002/03/29 19:06:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <ctype.h> #include <ctype.h>
#include "access/heapam.h" #include "access/heapam.h"
#include "catalog/pg_type.h"
#include "commands/creatinh.h" #include "commands/creatinh.h"
#include "commands/sequence.h" #include "commands/sequence.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -85,8 +86,6 @@ DefineSequence(CreateSeqStmt *seq) ...@@ -85,8 +86,6 @@ DefineSequence(CreateSeqStmt *seq)
{ {
FormData_pg_sequence new; FormData_pg_sequence new;
CreateStmt *stmt = makeNode(CreateStmt); CreateStmt *stmt = makeNode(CreateStmt);
ColumnDef *coldef;
TypeName *typnam;
Oid seqoid; Oid seqoid;
Relation rel; Relation rel;
Buffer buf; Buffer buf;
...@@ -108,9 +107,12 @@ DefineSequence(CreateSeqStmt *seq) ...@@ -108,9 +107,12 @@ DefineSequence(CreateSeqStmt *seq)
stmt->tableElts = NIL; stmt->tableElts = NIL;
for (i = SEQ_COL_FIRSTCOL; i <= SEQ_COL_LASTCOL; i++) for (i = SEQ_COL_FIRSTCOL; i <= SEQ_COL_LASTCOL; i++)
{ {
ColumnDef *coldef;
TypeName *typnam;
typnam = makeNode(TypeName); typnam = makeNode(TypeName);
typnam->setof = FALSE; typnam->setof = FALSE;
typnam->arrayBounds = NULL; typnam->arrayBounds = NIL;
typnam->typmod = -1; typnam->typmod = -1;
coldef = makeNode(ColumnDef); coldef = makeNode(ColumnDef);
coldef->typename = typnam; coldef->typename = typnam;
...@@ -122,48 +124,48 @@ DefineSequence(CreateSeqStmt *seq) ...@@ -122,48 +124,48 @@ DefineSequence(CreateSeqStmt *seq)
switch (i) switch (i)
{ {
case SEQ_COL_NAME: case SEQ_COL_NAME:
typnam->name = "name"; typnam->typeid = NAMEOID;
coldef->colname = "sequence_name"; coldef->colname = "sequence_name";
namestrcpy(&name, seq->sequence->relname); namestrcpy(&name, seq->sequence->relname);
value[i - 1] = NameGetDatum(&name); value[i - 1] = NameGetDatum(&name);
break; break;
case SEQ_COL_LASTVAL: case SEQ_COL_LASTVAL:
typnam->name = "int8"; typnam->typeid = INT8OID;
coldef->colname = "last_value"; coldef->colname = "last_value";
value[i - 1] = Int64GetDatumFast(new.last_value); value[i - 1] = Int64GetDatumFast(new.last_value);
break; break;
case SEQ_COL_INCBY: case SEQ_COL_INCBY:
typnam->name = "int8"; typnam->typeid = INT8OID;
coldef->colname = "increment_by"; coldef->colname = "increment_by";
value[i - 1] = Int64GetDatumFast(new.increment_by); value[i - 1] = Int64GetDatumFast(new.increment_by);
break; break;
case SEQ_COL_MAXVALUE: case SEQ_COL_MAXVALUE:
typnam->name = "int8"; typnam->typeid = INT8OID;
coldef->colname = "max_value"; coldef->colname = "max_value";
value[i - 1] = Int64GetDatumFast(new.max_value); value[i - 1] = Int64GetDatumFast(new.max_value);
break; break;
case SEQ_COL_MINVALUE: case SEQ_COL_MINVALUE:
typnam->name = "int8"; typnam->typeid = INT8OID;
coldef->colname = "min_value"; coldef->colname = "min_value";
value[i - 1] = Int64GetDatumFast(new.min_value); value[i - 1] = Int64GetDatumFast(new.min_value);
break; break;
case SEQ_COL_CACHE: case SEQ_COL_CACHE:
typnam->name = "int8"; typnam->typeid = INT8OID;
coldef->colname = "cache_value"; coldef->colname = "cache_value";
value[i - 1] = Int64GetDatumFast(new.cache_value); value[i - 1] = Int64GetDatumFast(new.cache_value);
break; break;
case SEQ_COL_LOG: case SEQ_COL_LOG:
typnam->name = "int8"; typnam->typeid = INT8OID;
coldef->colname = "log_cnt"; coldef->colname = "log_cnt";
value[i - 1] = Int64GetDatum((int64) 1); value[i - 1] = Int64GetDatum((int64) 1);
break; break;
case SEQ_COL_CYCLE: case SEQ_COL_CYCLE:
typnam->name = "bool"; typnam->typeid = BOOLOID;
coldef->colname = "is_cycled"; coldef->colname = "is_cycled";
value[i - 1] = BoolGetDatum(new.is_cycled); value[i - 1] = BoolGetDatum(new.is_cycled);
break; break;
case SEQ_COL_CALLED: case SEQ_COL_CALLED:
typnam->name = "bool"; typnam->typeid = BOOLOID;
coldef->colname = "is_called"; coldef->colname = "is_called";
value[i - 1] = BoolGetDatum(false); value[i - 1] = BoolGetDatum(false);
break; break;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.60 2002/03/06 06:09:39 momjian Exp $ * $Header: /cvsroot/pgsql/src/backend/commands/variable.c,v 1.61 2002/03/29 19:06:07 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -21,11 +21,12 @@ ...@@ -21,11 +21,12 @@
#include "access/xact.h" #include "access/xact.h"
#include "catalog/pg_shadow.h" #include "catalog/pg_shadow.h"
#include "catalog/pg_type.h"
#include "commands/variable.h" #include "commands/variable.h"
#include "miscadmin.h" #include "miscadmin.h"
#include "optimizer/cost.h" #include "optimizer/cost.h"
#include "optimizer/paths.h" #include "optimizer/paths.h"
#include "parser/parse_expr.h" #include "parser/parse_type.h"
#include "utils/builtins.h" #include "utils/builtins.h"
#include "utils/date.h" #include "utils/date.h"
#include "utils/guc.h" #include "utils/guc.h"
...@@ -390,7 +391,9 @@ parse_timezone(List *args) ...@@ -390,7 +391,9 @@ parse_timezone(List *args)
type = p->typename; type = p->typename;
if (type != NULL) if (type != NULL)
{ {
if (strcmp(type->name, "interval") == 0) Oid typeOid = typenameTypeId(type);
if (typeOid == INTERVALOID)
{ {
Interval *interval; Interval *interval;
...@@ -402,7 +405,7 @@ parse_timezone(List *args) ...@@ -402,7 +405,7 @@ parse_timezone(List *args)
elog(ERROR, "SET TIME ZONE illegal INTERVAL; month not allowed"); elog(ERROR, "SET TIME ZONE illegal INTERVAL; month not allowed");
CTimeZone = interval->time; CTimeZone = interval->time;
} }
else if (strcmp(type->name, "float8") == 0) else if (typeOid == FLOAT8OID)
{ {
float8 time; float8 time;
...@@ -414,7 +417,7 @@ parse_timezone(List *args) ...@@ -414,7 +417,7 @@ parse_timezone(List *args)
* We do not actually generate an integer constant in gram.y * We do not actually generate an integer constant in gram.y
* so this is not used... * so this is not used...
*/ */
else if (strcmp(type->name, "int4") == 0) else if (typeOid == INT4OID)
{ {
int32 time; int32 time;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Id: view.c,v 1.60 2002/03/22 02:56:31 tgl Exp $ * $Id: view.c,v 1.61 2002/03/29 19:06:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "access/xact.h" #include "access/xact.h"
#include "catalog/heap.h" #include "catalog/heap.h"
#include "catalog/namespace.h"
#include "commands/creatinh.h" #include "commands/creatinh.h"
#include "commands/view.h" #include "commands/view.h"
#include "miscadmin.h" #include "miscadmin.h"
...@@ -24,6 +25,7 @@ ...@@ -24,6 +25,7 @@
#include "rewrite/rewriteManip.h" #include "rewrite/rewriteManip.h"
#include "rewrite/rewriteRemove.h" #include "rewrite/rewriteRemove.h"
#include "rewrite/rewriteSupport.h" #include "rewrite/rewriteSupport.h"
#include "utils/syscache.h"
/*--------------------------------------------------------------------- /*---------------------------------------------------------------------
...@@ -38,10 +40,9 @@ ...@@ -38,10 +40,9 @@
*--------------------------------------------------------------------- *---------------------------------------------------------------------
*/ */
static Oid static Oid
DefineVirtualRelation(char *relname, List *tlist) DefineVirtualRelation(const RangeVar *relation, List *tlist)
{ {
CreateStmt *createStmt = makeNode(CreateStmt); CreateStmt *createStmt = makeNode(CreateStmt);
RangeVar *rel = makeNode(RangeVar);
List *attrList, List *attrList,
*t; *t;
...@@ -57,14 +58,12 @@ DefineVirtualRelation(char *relname, List *tlist) ...@@ -57,14 +58,12 @@ DefineVirtualRelation(char *relname, List *tlist)
if (!res->resjunk) if (!res->resjunk)
{ {
char *resname = res->resname;
char *restypename = typeidTypeName(res->restype);
ColumnDef *def = makeNode(ColumnDef); ColumnDef *def = makeNode(ColumnDef);
TypeName *typename = makeNode(TypeName); TypeName *typename = makeNode(TypeName);
def->colname = pstrdup(resname); def->colname = pstrdup(res->resname);
typename->name = pstrdup(restypename); typename->typeid = res->restype;
typename->typmod = res->restypmod; typename->typmod = res->restypmod;
def->typename = typename; def->typename = typename;
...@@ -84,10 +83,7 @@ DefineVirtualRelation(char *relname, List *tlist) ...@@ -84,10 +83,7 @@ DefineVirtualRelation(char *relname, List *tlist)
* now create the parameters for keys/inheritance etc. All of them are * now create the parameters for keys/inheritance etc. All of them are
* nil... * nil...
*/ */
rel->relname = relname; createStmt->relation = (RangeVar *) relation;
rel->schemaname = NULL; /* XXX wrong */
rel->istemp = false;
createStmt->relation = rel;
createStmt->tableElts = attrList; createStmt->tableElts = attrList;
createStmt->inhRelations = NIL; createStmt->inhRelations = NIL;
createStmt->constraints = NIL; createStmt->constraints = NIL;
...@@ -100,25 +96,19 @@ DefineVirtualRelation(char *relname, List *tlist) ...@@ -100,25 +96,19 @@ DefineVirtualRelation(char *relname, List *tlist)
} }
static RuleStmt * static RuleStmt *
FormViewRetrieveRule(char *viewName, Query *viewParse) FormViewRetrieveRule(const RangeVar *view, Query *viewParse)
{ {
RuleStmt *rule; RuleStmt *rule;
char *rname; char *rname;
RangeVar *rel;
/* /*
* Create a RuleStmt that corresponds to the suitable rewrite rule * Create a RuleStmt that corresponds to the suitable rewrite rule
* args for DefineQueryRewrite(); * args for DefineQueryRewrite();
*/ */
rname = MakeRetrieveViewRuleName(viewName); rname = MakeRetrieveViewRuleName(view->relname);
rel = makeNode(RangeVar);
rel->relname = pstrdup(viewName);
rel->inhOpt = INH_NO;
rel->alias = NULL;
rule = makeNode(RuleStmt); rule = makeNode(RuleStmt);
rule->relation = rel; rule->relation = copyObject((RangeVar *) view);
rule->rulename = pstrdup(rname); rule->rulename = pstrdup(rname);
rule->whereClause = NULL; rule->whereClause = NULL;
rule->event = CMD_SELECT; rule->event = CMD_SELECT;
...@@ -129,7 +119,7 @@ FormViewRetrieveRule(char *viewName, Query *viewParse) ...@@ -129,7 +119,7 @@ FormViewRetrieveRule(char *viewName, Query *viewParse)
} }
static void static void
DefineViewRules(char *viewName, Query *viewParse) DefineViewRules(const RangeVar *view, Query *viewParse)
{ {
RuleStmt *retrieve_rule; RuleStmt *retrieve_rule;
...@@ -139,13 +129,13 @@ DefineViewRules(char *viewName, Query *viewParse) ...@@ -139,13 +129,13 @@ DefineViewRules(char *viewName, Query *viewParse)
RuleStmt *delete_rule; RuleStmt *delete_rule;
#endif #endif
retrieve_rule = FormViewRetrieveRule(viewName, viewParse); retrieve_rule = FormViewRetrieveRule(view, viewParse);
#ifdef NOTYET #ifdef NOTYET
replace_rule = FormViewReplaceRule(viewName, viewParse); replace_rule = FormViewReplaceRule(view, viewParse);
append_rule = FormViewAppendRule(viewName, viewParse); append_rule = FormViewAppendRule(view, viewParse);
delete_rule = FormViewDeleteRule(viewName, viewParse); delete_rule = FormViewDeleteRule(view, viewParse);
#endif #endif
DefineQueryRewrite(retrieve_rule); DefineQueryRewrite(retrieve_rule);
...@@ -231,7 +221,7 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse) ...@@ -231,7 +221,7 @@ UpdateRangeTableOfViewParse(Oid viewOid, Query *viewParse)
*------------------------------------------------------------------- *-------------------------------------------------------------------
*/ */
void void
DefineView(char *viewName, Query *viewParse) DefineView(const RangeVar *view, Query *viewParse)
{ {
Oid viewOid; Oid viewOid;
...@@ -240,7 +230,7 @@ DefineView(char *viewName, Query *viewParse) ...@@ -240,7 +230,7 @@ DefineView(char *viewName, Query *viewParse)
* *
* NOTE: if it already exists, the xact will be aborted. * NOTE: if it already exists, the xact will be aborted.
*/ */
viewOid = DefineVirtualRelation(viewName, viewParse->targetList); viewOid = DefineVirtualRelation(view, viewParse->targetList);
/* /*
* The relation we have just created is not visible to any other * The relation we have just created is not visible to any other
...@@ -258,7 +248,7 @@ DefineView(char *viewName, Query *viewParse) ...@@ -258,7 +248,7 @@ DefineView(char *viewName, Query *viewParse)
/* /*
* Now create the rules associated with the view. * Now create the rules associated with the view.
*/ */
DefineViewRules(viewName, viewParse); DefineViewRules(view, viewParse);
} }
/*------------------------------------------------------------------ /*------------------------------------------------------------------
...@@ -268,11 +258,14 @@ DefineView(char *viewName, Query *viewParse) ...@@ -268,11 +258,14 @@ DefineView(char *viewName, Query *viewParse)
*------------------------------------------------------------------ *------------------------------------------------------------------
*/ */
void void
RemoveView(char *viewName) RemoveView(const RangeVar *view)
{ {
Oid viewOid;
viewOid = RangeVarGetRelid(view, false);
/* /*
* We just have to drop the relation; the associated rules will be * We just have to drop the relation; the associated rules will be
* cleaned up automatically. * cleaned up automatically.
*/ */
heap_drop_with_catalog(viewName, allowSystemTableMods); heap_drop_with_catalog(viewOid, allowSystemTableMods);
} }
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.173 2002/03/22 02:56:31 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/copyfuncs.c,v 1.174 2002/03/29 19:06:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1637,10 +1637,11 @@ _copyTypeName(TypeName *from) ...@@ -1637,10 +1637,11 @@ _copyTypeName(TypeName *from)
{ {
TypeName *newnode = makeNode(TypeName); TypeName *newnode = makeNode(TypeName);
if (from->name) Node_Copy(from, newnode, names);
newnode->name = pstrdup(from->name); newnode->typeid = from->typeid;
newnode->timezone = from->timezone; newnode->timezone = from->timezone;
newnode->setof = from->setof; newnode->setof = from->setof;
newnode->pct_type = from->pct_type;
newnode->typmod = from->typmod; newnode->typmod = from->typmod;
Node_Copy(from, newnode, arrayBounds); Node_Copy(from, newnode, arrayBounds);
...@@ -2008,7 +2009,7 @@ _copyDefineStmt(DefineStmt *from) ...@@ -2008,7 +2009,7 @@ _copyDefineStmt(DefineStmt *from)
DefineStmt *newnode = makeNode(DefineStmt); DefineStmt *newnode = makeNode(DefineStmt);
newnode->defType = from->defType; newnode->defType = from->defType;
newnode->defname = pstrdup(from->defname); Node_Copy(from, newnode, defnames);
Node_Copy(from, newnode, definition); Node_Copy(from, newnode, definition);
return newnode; return newnode;
...@@ -2089,7 +2090,7 @@ _copyProcedureStmt(ProcedureStmt *from) ...@@ -2089,7 +2090,7 @@ _copyProcedureStmt(ProcedureStmt *from)
ProcedureStmt *newnode = makeNode(ProcedureStmt); ProcedureStmt *newnode = makeNode(ProcedureStmt);
newnode->replace = from->replace; newnode->replace = from->replace;
newnode->funcname = pstrdup(from->funcname); Node_Copy(from, newnode, funcname);
Node_Copy(from, newnode, argTypes); Node_Copy(from, newnode, argTypes);
Node_Copy(from, newnode, returnType); Node_Copy(from, newnode, returnType);
Node_Copy(from, newnode, withClause); Node_Copy(from, newnode, withClause);
...@@ -2229,8 +2230,7 @@ _copyCreateDomainStmt(CreateDomainStmt *from) ...@@ -2229,8 +2230,7 @@ _copyCreateDomainStmt(CreateDomainStmt *from)
{ {
CreateDomainStmt *newnode = makeNode(CreateDomainStmt); CreateDomainStmt *newnode = makeNode(CreateDomainStmt);
if (from->domainname) Node_Copy(from, newnode, domainname);
newnode->domainname = pstrdup(from->domainname);
Node_Copy(from, newnode, typename); Node_Copy(from, newnode, typename);
Node_Copy(from, newnode, constraints); Node_Copy(from, newnode, constraints);
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.121 2002/03/22 02:56:31 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/equalfuncs.c,v 1.122 2002/03/29 19:06:08 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -836,7 +836,7 @@ _equalDefineStmt(DefineStmt *a, DefineStmt *b) ...@@ -836,7 +836,7 @@ _equalDefineStmt(DefineStmt *a, DefineStmt *b)
{ {
if (a->defType != b->defType) if (a->defType != b->defType)
return false; return false;
if (!equalstr(a->defname, b->defname)) if (!equal(a->defnames, b->defnames))
return false; return false;
if (!equal(a->definition, b->definition)) if (!equal(a->definition, b->definition))
return false; return false;
...@@ -928,7 +928,7 @@ _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b) ...@@ -928,7 +928,7 @@ _equalProcedureStmt(ProcedureStmt *a, ProcedureStmt *b)
{ {
if (a->replace != b->replace) if (a->replace != b->replace)
return false; return false;
if (!equalstr(a->funcname, b->funcname)) if (!equal(a->funcname, b->funcname))
return false; return false;
if (!equal(a->argTypes, b->argTypes)) if (!equal(a->argTypes, b->argTypes))
return false; return false;
...@@ -1071,7 +1071,7 @@ _equalLoadStmt(LoadStmt *a, LoadStmt *b) ...@@ -1071,7 +1071,7 @@ _equalLoadStmt(LoadStmt *a, LoadStmt *b)
static bool static bool
_equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b) _equalCreateDomainStmt(CreateDomainStmt *a, CreateDomainStmt *b)
{ {
if (!equalstr(a->domainname, b->domainname)) if (!equal(a->domainname, b->domainname))
return false; return false;
if (!equal(a->typename, b->typename)) if (!equal(a->typename, b->typename))
return false; return false;
...@@ -1572,12 +1572,16 @@ _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b) ...@@ -1572,12 +1572,16 @@ _equalRangeSubselect(RangeSubselect *a, RangeSubselect *b)
static bool static bool
_equalTypeName(TypeName *a, TypeName *b) _equalTypeName(TypeName *a, TypeName *b)
{ {
if (!equalstr(a->name, b->name)) if (!equal(a->names, b->names))
return false;
if (a->typeid != b->typeid)
return false; return false;
if (a->timezone != b->timezone) if (a->timezone != b->timezone)
return false; return false;
if (a->setof != b->setof) if (a->setof != b->setof)
return false; return false;
if (a->pct_type != b->pct_type)
return false;
if (a->typmod != b->typmod) if (a->typmod != b->typmod)
return false; return false;
if (!equal(a->arrayBounds, b->arrayBounds)) if (!equal(a->arrayBounds, b->arrayBounds))
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.29 2002/03/22 02:56:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/makefuncs.c,v 1.30 2002/03/29 19:06:09 tgl Exp $
*/ */
#include "postgres.h" #include "postgres.h"
...@@ -209,3 +209,17 @@ makeRangeVar(char *schemaname, char *relname) ...@@ -209,3 +209,17 @@ makeRangeVar(char *schemaname, char *relname)
return r; return r;
} }
/*
* makeTypeName -
* build a TypeName node for an unqualified name.
*/
TypeName *
makeTypeName(char *typnam)
{
TypeName *n = makeNode(TypeName);
n->names = makeList1(makeString(typnam));
n->typmod = -1;
return n;
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.151 2002/03/22 02:56:32 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/nodes/outfuncs.c,v 1.152 2002/03/29 19:06:09 tgl Exp $
* *
* NOTES * NOTES
* Every (plan) node in POSTGRES has an associated "out" routine which * Every (plan) node in POSTGRES has an associated "out" routine which
...@@ -187,11 +187,14 @@ _outColumnDef(StringInfo str, ColumnDef *node) ...@@ -187,11 +187,14 @@ _outColumnDef(StringInfo str, ColumnDef *node)
static void static void
_outTypeName(StringInfo str, TypeName *node) _outTypeName(StringInfo str, TypeName *node)
{ {
appendStringInfo(str, " TYPENAME :name "); appendStringInfo(str, " TYPENAME :names ");
_outToken(str, node->name); _outNode(str, node->names);
appendStringInfo(str, " :timezone %s :setof %s typmod %d :arrayBounds ", appendStringInfo(str, " :typeid %u :timezone %s :setof %s"
" :pct_type %s typmod %d :arrayBounds ",
node->typeid,
booltostr(node->timezone), booltostr(node->timezone),
booltostr(node->setof), booltostr(node->setof),
booltostr(node->pct_type),
node->typmod); node->typmod);
_outNode(str, node->arrayBounds); _outNode(str, node->arrayBounds);
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group * Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
* Portions Copyright (c) 1994, Regents of the University of California * Portions Copyright (c) 1994, Regents of the University of California
* *
* $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.223 2002/03/26 19:15:56 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/analyze.c,v 1.224 2002/03/29 19:06:10 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -108,11 +108,7 @@ static void transformIndexConstraints(ParseState *pstate, ...@@ -108,11 +108,7 @@ static void transformIndexConstraints(ParseState *pstate,
CreateStmtContext *cxt); CreateStmtContext *cxt);
static void transformFKConstraints(ParseState *pstate, static void transformFKConstraints(ParseState *pstate,
CreateStmtContext *cxt); CreateStmtContext *cxt);
static Node *transformTypeRefs(ParseState *pstate, Node *stmt);
static void applyColumnNames(List *dst, List *src); static void applyColumnNames(List *dst, List *src);
static void transformTypeRefsList(ParseState *pstate, List *l);
static void transformTypeRef(ParseState *pstate, TypeName *tn);
static List *getSetColTypes(ParseState *pstate, Node *node); static List *getSetColTypes(ParseState *pstate, Node *node);
static void transformForUpdate(Query *qry, List *forUpdate); static void transformForUpdate(Query *qry, List *forUpdate);
static void transformConstraintAttrs(List *constraintList); static void transformConstraintAttrs(List *constraintList);
...@@ -309,18 +305,6 @@ transformStmt(ParseState *pstate, Node *parseTree, ...@@ -309,18 +305,6 @@ transformStmt(ParseState *pstate, Node *parseTree,
(SelectStmt *) parseTree); (SelectStmt *) parseTree);
break; break;
/*
* Convert use of %TYPE in statements where it is permitted.
*/
case T_ProcedureStmt:
case T_CommentStmt:
case T_RemoveFuncStmt:
case T_DefineStmt:
result = makeNode(Query);
result->commandType = CMD_UTILITY;
result->utilityStmt = transformTypeRefs(pstate, parseTree);
break;
default: default:
/* /*
...@@ -792,17 +776,24 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt, ...@@ -792,17 +776,24 @@ transformColumnDefinition(ParseState *pstate, CreateStmtContext *cxt,
/* Check for SERIAL pseudo-types */ /* Check for SERIAL pseudo-types */
is_serial = false; is_serial = false;
if (strcmp(column->typename->name, "serial") == 0 || if (length(column->typename->names) == 1)
strcmp(column->typename->name, "serial4") == 0)
{
is_serial = true;
column->typename->name = pstrdup("int4");
}
else if (strcmp(column->typename->name, "bigserial") == 0 ||
strcmp(column->typename->name, "serial8") == 0)
{ {
is_serial = true; char *typname = strVal(lfirst(column->typename->names));
column->typename->name = pstrdup("int8");
if (strcmp(typname, "serial") == 0 ||
strcmp(typname, "serial4") == 0)
{
is_serial = true;
column->typename->names = NIL;
column->typename->typeid = INT4OID;
}
else if (strcmp(typname, "bigserial") == 0 ||
strcmp(typname, "serial8") == 0)
{
is_serial = true;
column->typename->names = NIL;
column->typename->typeid = INT8OID;
}
} }
/* Do necessary work on the column type declaration */ /* Do necessary work on the column type declaration */
...@@ -2634,110 +2625,6 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt, ...@@ -2634,110 +2625,6 @@ transformAlterTableStmt(ParseState *pstate, AlterTableStmt *stmt,
return qry; return qry;
} }
/*
* Transform uses of %TYPE in a statement.
*/
static Node *
transformTypeRefs(ParseState *pstate, Node *stmt)
{
switch (nodeTag(stmt))
{
case T_ProcedureStmt:
{
ProcedureStmt *ps = (ProcedureStmt *) stmt;
transformTypeRefsList(pstate, ps->argTypes);
transformTypeRef(pstate, (TypeName *) ps->returnType);
transformTypeRefsList(pstate, ps->withClause);
}
break;
case T_CommentStmt:
{
CommentStmt *cs = (CommentStmt *) stmt;
transformTypeRefsList(pstate, cs->objlist);
}
break;
case T_RemoveFuncStmt:
{
RemoveFuncStmt *rs = (RemoveFuncStmt *) stmt;
transformTypeRefsList(pstate, rs->args);
}
break;
case T_DefineStmt:
{
DefineStmt *ds = (DefineStmt *) stmt;
List *ele;
foreach(ele, ds->definition)
{
DefElem *de = (DefElem *) lfirst(ele);
if (de->arg != NULL
&& IsA(de->arg, TypeName))
transformTypeRef(pstate, (TypeName *) de->arg);
}
}
break;
default:
elog(ERROR, "Unsupported type %d in transformTypeRefs",
nodeTag(stmt));
break;
}
return stmt;
}
/*
* Transform uses of %TYPE in a list.
*/
static void
transformTypeRefsList(ParseState *pstate, List *l)
{
List *ele;
foreach(ele, l)
{
Node *elem = lfirst(ele);
if (elem && IsA(elem, TypeName))
transformTypeRef(pstate, (TypeName *) elem);
}
}
/*
* Transform a TypeName to not use %TYPE.
*/
static void
transformTypeRef(ParseState *pstate, TypeName *tn)
{
ColumnRef *cref;
Node *n;
Var *v;
char *tyn;
if (tn->attrname == NULL)
return;
/* XXX this needs work; can't type name be qualified? */
cref = makeNode(ColumnRef);
cref->fields = makeList2(makeString(tn->name), makeString(tn->attrname));
cref->indirection = NIL;
n = transformExpr(pstate, (Node *) cref);
if (!IsA(n, Var))
elog(ERROR, "unsupported expression in %%TYPE");
v = (Var *) n;
tyn = typeidTypeName(v->vartype);
elog(NOTICE, "%s.%s%%TYPE converted to %s", tn->name, tn->attrname, tyn);
tn->name = tyn;
tn->typmod = v->vartypmod;
tn->attrname = NULL;
}
/* exported so planner can check again after rewriting, query pullup, etc */ /* exported so planner can check again after rewriting, query pullup, etc */
void void
CheckSelectForUpdate(Query *qry) CheckSelectForUpdate(Query *qry)
...@@ -3059,15 +2946,7 @@ transformFkeyGetColType(CreateStmtContext *cxt, char *colname) ...@@ -3059,15 +2946,7 @@ transformFkeyGetColType(CreateStmtContext *cxt, char *colname)
ColumnDef *col = lfirst(cols); ColumnDef *col = lfirst(cols);
if (strcmp(col->colname, colname) == 0) if (strcmp(col->colname, colname) == 0)
{ return typenameTypeId(col->typename);
char *buff = TypeNameToInternalName(col->typename);
result = typenameTypeId(buff);
if (!OidIsValid(result))
elog(ERROR, "Unable to lookup type %s",
col->typename->name);
return result;
}
} }
/* Perhaps it's a system column name */ /* Perhaps it's a system column name */
sysatt = SystemAttributeByName(colname, cxt->hasoids); sysatt = SystemAttributeByName(colname, cxt->hasoids);
...@@ -3092,7 +2971,6 @@ transformFkeyGetColType(CreateStmtContext *cxt, char *colname) ...@@ -3092,7 +2971,6 @@ transformFkeyGetColType(CreateStmtContext *cxt, char *colname)
if (strcmp(name, colname) == 0) if (strcmp(name, colname) == 0)
{ {
result = rel->rd_att->attrs[count]->atttypid; result = rel->rd_att->attrs[count]->atttypid;
heap_close(rel, NoLock); heap_close(rel, NoLock);
return result; return result;
} }
...@@ -3111,7 +2989,6 @@ transformFkeyGetColType(CreateStmtContext *cxt, char *colname) ...@@ -3111,7 +2989,6 @@ transformFkeyGetColType(CreateStmtContext *cxt, char *colname)
if (HeapTupleIsValid(atttuple)) if (HeapTupleIsValid(atttuple))
{ {
result = ((Form_pg_attribute) GETSTRUCT(atttuple))->atttypid; result = ((Form_pg_attribute) GETSTRUCT(atttuple))->atttypid;
ReleaseSysCache(atttuple); ReleaseSysCache(atttuple);
return result; return result;
} }
...@@ -3233,7 +3110,7 @@ static void ...@@ -3233,7 +3110,7 @@ static void
transformColumnType(ParseState *pstate, ColumnDef *column) transformColumnType(ParseState *pstate, ColumnDef *column)
{ {
TypeName *typename = column->typename; TypeName *typename = column->typename;
Type ctype = typenameType(typename->name); Type ctype = typenameType(typename);
/* /*
* Is this the name of a complex type? If so, implement it as a set. * Is this the name of a complex type? If so, implement it as a set.
......
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.111 2002/03/21 16:01:03 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_expr.c,v 1.112 2002/03/29 19:06:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -1103,7 +1103,7 @@ parser_typecast_constant(Value *expr, TypeName *typename) ...@@ -1103,7 +1103,7 @@ parser_typecast_constant(Value *expr, TypeName *typename)
bool string_palloced = false; bool string_palloced = false;
bool isNull = false; bool isNull = false;
tp = typenameType(TypeNameToInternalName(typename)); tp = typenameType(typename);
switch (nodeTag(expr)) switch (nodeTag(expr))
{ {
...@@ -1161,7 +1161,7 @@ parser_typecast_expression(ParseState *pstate, ...@@ -1161,7 +1161,7 @@ parser_typecast_expression(ParseState *pstate,
Oid inputType = exprType(expr); Oid inputType = exprType(expr);
Oid targetType; Oid targetType;
targetType = typenameTypeId(TypeNameToInternalName(typename)); targetType = typenameTypeId(typename);
if (inputType == InvalidOid) if (inputType == InvalidOid)
return expr; /* do nothing if NULL input */ return expr; /* do nothing if NULL input */
...@@ -1185,27 +1185,3 @@ parser_typecast_expression(ParseState *pstate, ...@@ -1185,27 +1185,3 @@ parser_typecast_expression(ParseState *pstate,
return expr; return expr;
} }
/*
* Given a TypeName node as returned by the grammar, generate the internal
* name of the corresponding type. Note this does NOT check if the type
* exists or not.
*/
char *
TypeNameToInternalName(TypeName *typename)
{
Assert(typename->attrname == NULL);
if (typename->arrayBounds != NIL)
{
/*
* By convention, the name of an array type is the name of its
* element type with "_" prepended.
*/
char *arrayname = palloc(strlen(typename->name) + 2);
sprintf(arrayname, "_%s", typename->name);
return arrayname;
}
else
return typename->name;
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.120 2002/03/22 02:56:34 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/parser/parse_func.c,v 1.121 2002/03/29 19:06:11 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include "catalog/indexing.h" #include "catalog/indexing.h"
#include "catalog/pg_aggregate.h" #include "catalog/pg_aggregate.h"
#include "catalog/pg_inherits.h" #include "catalog/pg_inherits.h"
#include "catalog/pg_namespace.h"
#include "catalog/pg_proc.h" #include "catalog/pg_proc.h"
#include "nodes/makefuncs.h" #include "nodes/makefuncs.h"
#include "parser/parse_agg.h" #include "parser/parse_agg.h"
...@@ -969,9 +970,14 @@ func_get_detail(char *funcname, ...@@ -969,9 +970,14 @@ func_get_detail(char *funcname,
{ {
Oid targetType; Oid targetType;
targetType = GetSysCacheOid(TYPENAME, /* XXX WRONG: need to search searchpath for name; but little
* point in fixing before we revise this code for qualified
* funcnames too.
*/
targetType = GetSysCacheOid(TYPENAMENSP,
PointerGetDatum(funcname), PointerGetDatum(funcname),
0, 0, 0); ObjectIdGetDatum(PG_CATALOG_NAMESPACE),
0, 0);
if (OidIsValid(targetType) && if (OidIsValid(targetType) &&
!ISCOMPLEX(targetType)) !ISCOMPLEX(targetType))
{ {
...@@ -1222,13 +1228,11 @@ find_inheritors(Oid relid, Oid **supervec) ...@@ -1222,13 +1228,11 @@ find_inheritors(Oid relid, Oid **supervec)
{ {
/* return the type id, rather than the relation id */ /* return the type id, rather than the relation id */
Relation rd; Relation rd;
Oid trelid;
relid = lfirsti(elt); relid = lfirsti(elt);
rd = heap_open(relid, NoLock); rd = heap_open(relid, NoLock);
trelid = typenameTypeId(RelationGetRelationName(rd)); *relidvec++ = rd->rd_rel->reltype;
heap_close(rd, NoLock); heap_close(rd, NoLock);
*relidvec++ = trelid;
} }
} }
else else
...@@ -1473,7 +1477,9 @@ ParseComplexProjection(ParseState *pstate, ...@@ -1473,7 +1477,9 @@ ParseComplexProjection(ParseState *pstate,
* argument types * argument types
*/ */
void void
func_error(char *caller, char *funcname, int nargs, Oid *argtypes, char *msg) func_error(const char *caller, const char *funcname,
int nargs, const Oid *argtypes,
const char *msg)
{ {
char p[(NAMEDATALEN + 2) * FUNC_MAX_ARGS], char p[(NAMEDATALEN + 2) * FUNC_MAX_ARGS],
*ptr; *ptr;
...@@ -1488,9 +1494,9 @@ func_error(char *caller, char *funcname, int nargs, Oid *argtypes, char *msg) ...@@ -1488,9 +1494,9 @@ func_error(char *caller, char *funcname, int nargs, Oid *argtypes, char *msg)
*ptr++ = ','; *ptr++ = ',';
*ptr++ = ' '; *ptr++ = ' ';
} }
if (argtypes[i] != 0) if (OidIsValid(argtypes[i]))
{ {
strcpy(ptr, typeidTypeName(argtypes[i])); strncpy(ptr, typeidTypeName(argtypes[i]), NAMEDATALEN);
*(ptr + NAMEDATALEN) = '\0'; *(ptr + NAMEDATALEN) = '\0';
} }
else else
......
This diff is collapsed.
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.46 2002/03/21 23:27:23 tgl Exp $ * $Header: /cvsroot/pgsql/src/backend/rewrite/rewriteRemove.c,v 1.47 2002/03/29 19:06:13 tgl Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -30,11 +30,12 @@ ...@@ -30,11 +30,12 @@
/* /*
* RemoveRewriteRule * RemoveRewriteRule
* *
* Delete a rule given its rulename. * Delete a rule given its (possibly qualified) rulename.
*/ */
void void
RemoveRewriteRule(char *ruleName) RemoveRewriteRule(List *names)
{ {
char *ruleName;
Relation RewriteRelation; Relation RewriteRelation;
Relation event_relation; Relation event_relation;
HeapTuple tuple; HeapTuple tuple;
...@@ -43,6 +44,13 @@ RemoveRewriteRule(char *ruleName) ...@@ -43,6 +44,13 @@ RemoveRewriteRule(char *ruleName)
bool hasMoreRules; bool hasMoreRules;
int32 aclcheck_result; int32 aclcheck_result;
/*
* XXX temporary until rules become schema-tized
*/
if (length(names) != 1)
elog(ERROR, "Qualified rule names not supported yet");
ruleName = strVal(lfirst(names));
/* /*
* Open the pg_rewrite relation. * Open the pg_rewrite relation.
*/ */
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment