1996-07-09 08:22:35 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
1999-02-14 00:22:53 +01:00
|
|
|
* pg_type.c
|
1997-09-07 07:04:48 +02:00
|
|
|
* routines to support manipulation of the pg_type relation
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-06-20 22:29:54 +02:00
|
|
|
* Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* IDENTIFICATION
|
2002-07-24 21:11:14 +02:00
|
|
|
* $Header: /cvsroot/pgsql/src/backend/catalog/pg_type.c,v 1.76 2002/07/24 19:11:09 petere Exp $
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "postgres.h"
|
|
|
|
|
|
|
|
#include "access/heapam.h"
|
|
|
|
#include "catalog/catname.h"
|
2002-07-12 20:43:19 +02:00
|
|
|
#include "catalog/dependency.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "catalog/indexing.h"
|
|
|
|
#include "catalog/pg_type.h"
|
|
|
|
#include "miscadmin.h"
|
|
|
|
#include "utils/builtins.h"
|
2002-07-18 18:47:26 +02:00
|
|
|
#include "utils/lsyscache.h"
|
1998-04-27 06:08:07 +02:00
|
|
|
#include "utils/syscache.h"
|
|
|
|
|
1996-11-04 00:27:08 +01:00
|
|
|
|
1996-07-09 08:22:35 +02:00
|
|
|
/* ----------------------------------------------------------------
|
2002-03-29 20:06:29 +01:00
|
|
|
* TypeShellMake
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-03-29 20:06:29 +01:00
|
|
|
* This procedure inserts a "shell" tuple into the type
|
|
|
|
* relation. The type tuple inserted has invalid values
|
|
|
|
* and in particular, the "typisdefined" field is false.
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2002-03-29 20:06:29 +01:00
|
|
|
* This is used so that a tuple exists in the catalogs.
|
|
|
|
* The invalid fields should be fixed up sometime after
|
|
|
|
* this routine is called, and then the "typeisdefined"
|
|
|
|
* field is set to true. -cim 6/15/90
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Oid
|
2002-03-29 20:06:29 +01:00
|
|
|
TypeShellMake(const char *typeName, Oid typeNamespace)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation pg_type_desc;
|
2002-03-29 20:06:29 +01:00
|
|
|
TupleDesc tupDesc;
|
1998-02-26 05:46:47 +01:00
|
|
|
int i;
|
1997-09-08 04:41:22 +02:00
|
|
|
HeapTuple tup;
|
|
|
|
Datum values[Natts_pg_type];
|
|
|
|
char nulls[Natts_pg_type];
|
|
|
|
Oid typoid;
|
1998-04-01 17:35:33 +02:00
|
|
|
NameData name;
|
2002-03-29 20:06:29 +01:00
|
|
|
|
|
|
|
Assert(PointerIsValid(typeName));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* open pg_type
|
|
|
|
*/
|
|
|
|
pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock);
|
|
|
|
tupDesc = pg_type_desc->rd_att;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* initialize our *nulls and *values arrays
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
for (i = 0; i < Natts_pg_type; ++i)
|
|
|
|
{
|
|
|
|
nulls[i] = ' ';
|
|
|
|
values[i] = (Datum) NULL; /* redundant, but safe */
|
|
|
|
}
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* initialize *values with the type name and dummy values
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
i = 0;
|
1998-04-01 17:35:33 +02:00
|
|
|
namestrcpy(&name, typeName);
|
2002-03-29 20:06:29 +01:00
|
|
|
values[i++] = NameGetDatum(&name); /* typname */
|
|
|
|
values[i++] = ObjectIdGetDatum(typeNamespace); /* typnamespace */
|
|
|
|
values[i++] = ObjectIdGetDatum(InvalidOid); /* typowner */
|
|
|
|
values[i++] = Int16GetDatum(0); /* typlen */
|
|
|
|
values[i++] = BoolGetDatum(false); /* typbyval */
|
|
|
|
values[i++] = CharGetDatum(0); /* typtype */
|
|
|
|
values[i++] = BoolGetDatum(false); /* typisdefined */
|
|
|
|
values[i++] = CharGetDatum(0); /* typdelim */
|
|
|
|
values[i++] = ObjectIdGetDatum(InvalidOid); /* typrelid */
|
|
|
|
values[i++] = ObjectIdGetDatum(InvalidOid); /* typelem */
|
|
|
|
values[i++] = ObjectIdGetDatum(InvalidOid); /* typinput */
|
|
|
|
values[i++] = ObjectIdGetDatum(InvalidOid); /* typoutput */
|
|
|
|
values[i++] = CharGetDatum('i'); /* typalign */
|
|
|
|
values[i++] = CharGetDatum('p'); /* typstorage */
|
|
|
|
values[i++] = BoolGetDatum(false); /* typnotnull */
|
|
|
|
values[i++] = ObjectIdGetDatum(InvalidOid); /* typbasetype */
|
|
|
|
values[i++] = Int32GetDatum(-1); /* typtypmod */
|
|
|
|
values[i++] = Int32GetDatum(0); /* typndims */
|
|
|
|
nulls[i++] = 'n'; /* typdefaultbin */
|
|
|
|
nulls[i++] = 'n'; /* typdefault */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-03-29 20:06:29 +01:00
|
|
|
* create a new type tuple
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
tup = heap_formtuple(tupDesc, values, nulls);
|
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* insert the tuple in the relation and get the tuple's oid.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2002-05-22 00:05:55 +02:00
|
|
|
typoid = simple_heap_insert(pg_type_desc, tup);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-09-01 05:29:17 +02:00
|
|
|
if (RelationGetForm(pg_type_desc)->relhasindex)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation idescs[Num_pg_type_indices];
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
|
|
|
|
CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
|
|
|
|
CatalogCloseIndices(Num_pg_type_indices, idescs);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
2001-03-22 07:16:21 +01:00
|
|
|
|
|
|
|
/*
|
2002-03-29 20:06:29 +01:00
|
|
|
* clean up and return the type-oid
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1999-12-16 23:20:03 +01:00
|
|
|
heap_freetuple(tup);
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(pg_type_desc, RowExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1999-02-03 22:18:02 +01:00
|
|
|
return typoid;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------
|
1997-09-07 07:04:48 +02:00
|
|
|
* TypeCreate
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
1997-09-07 07:04:48 +02:00
|
|
|
* This does all the necessary work needed to define a new type.
|
2001-02-12 21:07:21 +01:00
|
|
|
*
|
|
|
|
* NOTE: if assignedTypeOid is not InvalidOid, then that OID is assigned to
|
|
|
|
* the new type (which, therefore, cannot already exist as a shell type).
|
|
|
|
* This hack is only intended for use in creating a relation's associated
|
|
|
|
* type, where we need to have created the relation tuple already.
|
1996-07-09 08:22:35 +02:00
|
|
|
* ----------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
Oid
|
2002-03-29 20:06:29 +01:00
|
|
|
TypeCreate(const char *typeName,
|
|
|
|
Oid typeNamespace,
|
2001-02-12 21:07:21 +01:00
|
|
|
Oid assignedTypeOid,
|
2002-03-19 03:18:25 +01:00
|
|
|
Oid relationOid, /* only for 'c'atalog typeTypes */
|
1997-09-07 07:04:48 +02:00
|
|
|
int16 internalSize,
|
|
|
|
char typeType,
|
|
|
|
char typDelim,
|
2002-03-29 20:06:29 +01:00
|
|
|
Oid inputProcedure,
|
|
|
|
Oid outputProcedure,
|
|
|
|
Oid elementType,
|
|
|
|
Oid baseType,
|
|
|
|
const char *defaultTypeValue, /* human readable rep */
|
|
|
|
const char *defaultTypeBin, /* cooked rep */
|
1997-09-07 07:04:48 +02:00
|
|
|
bool passedByValue,
|
2000-07-04 01:10:14 +02:00
|
|
|
char alignment,
|
2002-03-19 03:18:25 +01:00
|
|
|
char storage,
|
|
|
|
int32 typeMod,
|
2002-03-29 20:06:29 +01:00
|
|
|
int32 typNDims, /* Array dimensions for baseType */
|
2002-03-20 20:45:13 +01:00
|
|
|
bool typeNotNull)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation pg_type_desc;
|
|
|
|
Oid typeObjectId;
|
|
|
|
HeapTuple tup;
|
|
|
|
char nulls[Natts_pg_type];
|
|
|
|
char replaces[Natts_pg_type];
|
|
|
|
Datum values[Natts_pg_type];
|
1998-04-01 17:35:33 +02:00
|
|
|
NameData name;
|
1997-09-08 04:41:22 +02:00
|
|
|
TupleDesc tupDesc;
|
2002-03-29 20:06:29 +01:00
|
|
|
int i;
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2001-10-25 07:50:21 +02:00
|
|
|
* validate size specifications: either positive (fixed-length) or -1
|
|
|
|
* (variable-length).
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2001-10-25 07:50:21 +02:00
|
|
|
if (!(internalSize > 0 || internalSize == -1))
|
2001-09-06 04:07:42 +02:00
|
|
|
elog(ERROR, "TypeCreate: invalid type internal size %d",
|
|
|
|
internalSize);
|
|
|
|
|
|
|
|
if (internalSize != -1 && storage != 'p')
|
|
|
|
elog(ERROR, "TypeCreate: fixed size types must have storage PLAIN");
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-03-29 20:06:29 +01:00
|
|
|
* initialize arrays needed for heap_formtuple or heap_modifytuple
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
for (i = 0; i < Natts_pg_type; ++i)
|
|
|
|
{
|
|
|
|
nulls[i] = ' ';
|
|
|
|
replaces[i] = 'r';
|
2001-09-06 04:07:42 +02:00
|
|
|
values[i] = (Datum) 0;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* initialize the *values information
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
|
|
|
i = 0;
|
1998-09-01 06:40:42 +02:00
|
|
|
namestrcpy(&name, typeName);
|
2002-03-29 20:06:29 +01:00
|
|
|
values[i++] = NameGetDatum(&name); /* typname */
|
|
|
|
values[i++] = ObjectIdGetDatum(typeNamespace); /* typnamespace */
|
|
|
|
values[i++] = Int32GetDatum(GetUserId()); /* typowner */
|
|
|
|
values[i++] = Int16GetDatum(internalSize); /* typlen */
|
|
|
|
values[i++] = BoolGetDatum(passedByValue); /* typbyval */
|
|
|
|
values[i++] = CharGetDatum(typeType); /* typtype */
|
|
|
|
values[i++] = BoolGetDatum(true); /* typisdefined */
|
|
|
|
values[i++] = CharGetDatum(typDelim); /* typdelim */
|
|
|
|
values[i++] = ObjectIdGetDatum(typeType == 'c' ? relationOid : InvalidOid); /* typrelid */
|
|
|
|
values[i++] = ObjectIdGetDatum(elementType); /* typelem */
|
|
|
|
values[i++] = ObjectIdGetDatum(inputProcedure); /* typinput */
|
|
|
|
values[i++] = ObjectIdGetDatum(outputProcedure); /* typoutput */
|
|
|
|
values[i++] = CharGetDatum(alignment); /* typalign */
|
|
|
|
values[i++] = CharGetDatum(storage); /* typstorage */
|
|
|
|
values[i++] = BoolGetDatum(typeNotNull); /* typnotnull */
|
|
|
|
values[i++] = ObjectIdGetDatum(baseType); /* typbasetype */
|
|
|
|
values[i++] = Int32GetDatum(typeMod); /* typtypmod */
|
|
|
|
values[i++] = Int32GetDatum(typNDims); /* typndims */
|
2002-03-19 03:18:25 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the default binary value for this type. Check for
|
|
|
|
* nulls of course.
|
|
|
|
*/
|
|
|
|
if (defaultTypeBin)
|
|
|
|
values[i] = DirectFunctionCall1(textin,
|
2002-03-20 20:45:13 +01:00
|
|
|
CStringGetDatum(defaultTypeBin));
|
2002-03-19 03:18:25 +01:00
|
|
|
else
|
|
|
|
nulls[i] = 'n';
|
2002-03-29 20:06:29 +01:00
|
|
|
i++; /* typdefaultbin */
|
2002-03-19 03:18:25 +01:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
|
|
|
* initialize the default value for this type.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
2001-09-06 04:07:42 +02:00
|
|
|
if (defaultTypeValue)
|
|
|
|
values[i] = DirectFunctionCall1(textin,
|
2002-03-20 20:45:13 +01:00
|
|
|
CStringGetDatum(defaultTypeValue));
|
2001-09-06 04:07:42 +02:00
|
|
|
else
|
|
|
|
nulls[i] = 'n';
|
2002-03-29 20:06:29 +01:00
|
|
|
i++; /* typdefault */
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-03-22 07:16:21 +01:00
|
|
|
/*
|
2002-03-29 20:06:29 +01:00
|
|
|
* open pg_type and prepare to insert or update a row.
|
|
|
|
*
|
|
|
|
* NOTE: updating will not work correctly in bootstrap mode; but we don't
|
|
|
|
* expect to be overwriting any shell types in bootstrap mode.
|
1997-09-07 07:04:48 +02:00
|
|
|
*/
|
1999-09-18 21:08:25 +02:00
|
|
|
pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
tup = SearchSysCacheCopy(TYPENAMENSP,
|
|
|
|
CStringGetDatum(typeName),
|
|
|
|
ObjectIdGetDatum(typeNamespace),
|
|
|
|
0, 0);
|
1997-09-07 07:04:48 +02:00
|
|
|
if (HeapTupleIsValid(tup))
|
|
|
|
{
|
2002-03-29 20:06:29 +01:00
|
|
|
/*
|
|
|
|
* check that the type is not already defined. It may exist as a
|
|
|
|
* shell type, however (but only if assignedTypeOid is not given).
|
|
|
|
*/
|
|
|
|
if (((Form_pg_type) GETSTRUCT(tup))->typisdefined ||
|
|
|
|
assignedTypeOid != InvalidOid)
|
2001-08-10 17:49:39 +02:00
|
|
|
elog(ERROR, "type %s already exists", typeName);
|
2001-02-12 21:07:21 +01:00
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
/*
|
|
|
|
* Okay to update existing "shell" type tuple
|
|
|
|
*/
|
1997-09-07 07:04:48 +02:00
|
|
|
tup = heap_modifytuple(tup,
|
|
|
|
pg_type_desc,
|
|
|
|
values,
|
|
|
|
nulls,
|
|
|
|
replaces);
|
|
|
|
|
2001-01-23 05:32:23 +01:00
|
|
|
simple_heap_update(pg_type_desc, &tup->t_self, tup);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-07-20 07:16:59 +02:00
|
|
|
AssertTupleDescHasOid(pg_type_desc->rd_att);
|
|
|
|
typeObjectId = HeapTupleGetOid(tup);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
tupDesc = pg_type_desc->rd_att;
|
|
|
|
|
|
|
|
tup = heap_formtuple(tupDesc,
|
|
|
|
values,
|
|
|
|
nulls);
|
|
|
|
|
2001-02-12 21:07:21 +01:00
|
|
|
/* preassign tuple Oid, if one was given */
|
2002-07-20 07:16:59 +02:00
|
|
|
AssertTupleDescHasOid(tupDesc);
|
|
|
|
HeapTupleSetOid(tup, assignedTypeOid);
|
2001-02-12 21:07:21 +01:00
|
|
|
|
2002-05-22 00:05:55 +02:00
|
|
|
typeObjectId = simple_heap_insert(pg_type_desc, tup);
|
1997-09-07 07:04:48 +02:00
|
|
|
}
|
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
/* Update indices (not necessary if bootstrapping) */
|
1998-09-01 05:29:17 +02:00
|
|
|
if (RelationGetForm(pg_type_desc)->relhasindex)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation idescs[Num_pg_type_indices];
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
|
|
|
|
CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tup);
|
|
|
|
CatalogCloseIndices(Num_pg_type_indices, idescs);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
1999-09-18 21:08:25 +02:00
|
|
|
|
2002-07-12 20:43:19 +02:00
|
|
|
/*
|
2002-07-18 18:47:26 +02:00
|
|
|
* Create dependencies. We can/must skip this in bootstrap mode.
|
2002-07-12 20:43:19 +02:00
|
|
|
*/
|
2002-07-18 18:47:26 +02:00
|
|
|
if (!IsBootstrapProcessingMode())
|
2002-07-12 20:43:19 +02:00
|
|
|
{
|
2002-07-18 18:47:26 +02:00
|
|
|
ObjectAddress myself,
|
|
|
|
referenced;
|
|
|
|
|
|
|
|
myself.classId = RelOid_pg_type;
|
|
|
|
myself.objectId = typeObjectId;
|
|
|
|
myself.objectSubId = 0;
|
|
|
|
|
|
|
|
/* dependency on namespace */
|
|
|
|
/* skip for relation rowtype, since we have indirect dependency */
|
|
|
|
if (!OidIsValid(relationOid))
|
|
|
|
{
|
|
|
|
referenced.classId = get_system_catalog_relid(NamespaceRelationName);
|
|
|
|
referenced.objectId = typeNamespace;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal dependencies on the I/O functions */
|
2002-07-12 20:43:19 +02:00
|
|
|
referenced.classId = RelOid_pg_proc;
|
2002-07-18 18:47:26 +02:00
|
|
|
referenced.objectId = inputProcedure;
|
2002-07-12 20:43:19 +02:00
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
|
|
|
|
referenced.classId = RelOid_pg_proc;
|
2002-07-18 18:47:26 +02:00
|
|
|
referenced.objectId = outputProcedure;
|
2002-07-12 20:43:19 +02:00
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
|
2002-07-18 18:47:26 +02:00
|
|
|
/*
|
|
|
|
* If the type is a rowtype for a relation, mark it as internally
|
|
|
|
* dependent on the relation. This allows it to be auto-dropped
|
|
|
|
* when the relation is, and not otherwise.
|
|
|
|
*/
|
|
|
|
if (OidIsValid(relationOid))
|
|
|
|
{
|
|
|
|
referenced.classId = RelOid_pg_class;
|
|
|
|
referenced.objectId = relationOid;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_INTERNAL);
|
|
|
|
}
|
2002-07-12 20:43:19 +02:00
|
|
|
|
2002-07-18 18:47:26 +02:00
|
|
|
/*
|
|
|
|
* If the type is an array type, mark it auto-dependent on the base
|
|
|
|
* type. (This is a compromise between the typical case where the
|
|
|
|
* array type is automatically generated and the case where it is
|
|
|
|
* manually created: we'd prefer INTERNAL for the former case and
|
|
|
|
* NORMAL for the latter.)
|
|
|
|
*/
|
|
|
|
if (OidIsValid(elementType))
|
|
|
|
{
|
|
|
|
referenced.classId = RelOid_pg_type;
|
|
|
|
referenced.objectId = elementType;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_AUTO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Normal dependency from a domain to its base type. */
|
|
|
|
if (OidIsValid(baseType))
|
|
|
|
{
|
|
|
|
referenced.classId = RelOid_pg_type;
|
|
|
|
referenced.objectId = baseType;
|
|
|
|
referenced.objectSubId = 0;
|
|
|
|
recordDependencyOn(&myself, &referenced, DEPENDENCY_NORMAL);
|
|
|
|
}
|
2002-07-12 20:43:19 +02:00
|
|
|
}
|
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
/*
|
|
|
|
* finish up
|
|
|
|
*/
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(pg_type_desc, RowExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-19 04:04:17 +02:00
|
|
|
return typeObjectId;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
/*
|
|
|
|
* TypeRename
|
1997-09-07 07:04:48 +02:00
|
|
|
* This renames a type
|
2002-03-29 20:06:29 +01:00
|
|
|
*
|
|
|
|
* Note: any associated array type is *not* renamed; caller must make
|
|
|
|
* another call to handle that case. Currently this is only used for
|
|
|
|
* renaming types associated with tables, for which there are no arrays.
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
|
|
|
void
|
2002-03-29 20:06:29 +01:00
|
|
|
TypeRename(const char *oldTypeName, Oid typeNamespace,
|
|
|
|
const char *newTypeName)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
Relation pg_type_desc;
|
|
|
|
Relation idescs[Num_pg_type_indices];
|
2000-11-16 23:30:52 +01:00
|
|
|
HeapTuple tuple;
|
1998-09-01 06:40:42 +02:00
|
|
|
|
1999-09-18 21:08:25 +02:00
|
|
|
pg_type_desc = heap_openr(TypeRelationName, RowExclusiveLock);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
tuple = SearchSysCacheCopy(TYPENAMENSP,
|
|
|
|
CStringGetDatum(oldTypeName),
|
|
|
|
ObjectIdGetDatum(typeNamespace),
|
|
|
|
0, 0);
|
2000-11-16 23:30:52 +01:00
|
|
|
if (!HeapTupleIsValid(tuple))
|
2001-08-10 17:49:39 +02:00
|
|
|
elog(ERROR, "type %s does not exist", oldTypeName);
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2002-03-29 20:06:29 +01:00
|
|
|
if (SearchSysCacheExists(TYPENAMENSP,
|
|
|
|
CStringGetDatum(newTypeName),
|
|
|
|
ObjectIdGetDatum(typeNamespace),
|
|
|
|
0, 0))
|
2001-08-10 17:49:39 +02:00
|
|
|
elog(ERROR, "type named %s already exists", newTypeName);
|
1998-09-01 06:40:42 +02:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
namestrcpy(&(((Form_pg_type) GETSTRUCT(tuple))->typname), newTypeName);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2001-01-23 05:32:23 +01:00
|
|
|
simple_heap_update(pg_type_desc, &tuple->t_self, tuple);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
1998-08-19 04:04:17 +02:00
|
|
|
/* update the system catalog indices */
|
|
|
|
CatalogOpenIndices(Num_pg_type_indices, Name_pg_type_indices, idescs);
|
2000-11-16 23:30:52 +01:00
|
|
|
CatalogIndexInsert(idescs, Num_pg_type_indices, pg_type_desc, tuple);
|
1998-08-19 04:04:17 +02:00
|
|
|
CatalogCloseIndices(Num_pg_type_indices, idescs);
|
1997-09-07 07:04:48 +02:00
|
|
|
|
2000-11-16 23:30:52 +01:00
|
|
|
heap_freetuple(tuple);
|
1999-09-18 21:08:25 +02:00
|
|
|
heap_close(pg_type_desc, RowExclusiveLock);
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* makeArrayTypeName(typeName);
|
1997-09-07 07:04:48 +02:00
|
|
|
* - given a base type name, make an array of type name out of it
|
1996-07-09 08:22:35 +02:00
|
|
|
*
|
2001-10-12 02:07:15 +02:00
|
|
|
* the caller is responsible for pfreeing the result
|
1996-07-09 08:22:35 +02:00
|
|
|
*/
|
1998-02-26 05:46:47 +01:00
|
|
|
char *
|
2002-03-29 20:06:29 +01:00
|
|
|
makeArrayTypeName(const char *typeName)
|
1996-07-09 08:22:35 +02:00
|
|
|
{
|
1997-09-08 04:41:22 +02:00
|
|
|
char *arr;
|
1997-09-07 07:04:48 +02:00
|
|
|
|
|
|
|
if (!typeName)
|
|
|
|
return NULL;
|
2001-10-12 02:07:15 +02:00
|
|
|
arr = palloc(NAMEDATALEN);
|
|
|
|
snprintf(arr, NAMEDATALEN,
|
|
|
|
"_%.*s", NAMEDATALEN - 2, typeName);
|
1997-09-07 07:04:48 +02:00
|
|
|
return arr;
|
1996-07-09 08:22:35 +02:00
|
|
|
}
|