mirror of
https://github.com/postgres/postgres.git
synced 2025-11-15 03:41:20 +03:00
ALTER TABLE DROP COLUMN works. Patch by Christopher Kings-Lynne,
code review by Tom Lane. Remaining issues: functions that take or return tuple types are likely to break if one drops (or adds!) a column in the table defining the type. Need to think about what to do here. Along the way: some code review for recent COPY changes; mark system columns attnotnull = true where appropriate, per discussion a month ago.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.30 2002/06/20 20:29:37 momjian Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/adt/Attic/not_in.c,v 1.31 2002/08/02 18:15:07 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -28,9 +28,9 @@
|
||||
|
||||
#include "access/heapam.h"
|
||||
#include "catalog/namespace.h"
|
||||
#include "parser/parse_relation.h"
|
||||
#include "utils/builtins.h"
|
||||
|
||||
static int my_varattno(Relation rd, char *a);
|
||||
|
||||
/* ----------------------------------------------------------------
|
||||
*
|
||||
@@ -65,15 +65,10 @@ int4notin(PG_FUNCTION_ARGS)
|
||||
relrv = makeRangeVarFromNameList(names);
|
||||
|
||||
/* Open the relation and get a relation descriptor */
|
||||
|
||||
relation_to_scan = heap_openrv(relrv, AccessShareLock);
|
||||
|
||||
/* Find the column to search */
|
||||
|
||||
attrid = my_varattno(relation_to_scan, attribute);
|
||||
if (attrid < 0)
|
||||
elog(ERROR, "int4notin: unknown attribute %s for relation %s",
|
||||
attribute, RelationGetRelationName(relation_to_scan));
|
||||
attrid = attnameAttNum(relation_to_scan, attribute, true);
|
||||
|
||||
scan_descriptor = heap_beginscan(relation_to_scan, SnapshotNow,
|
||||
0, (ScanKey) NULL);
|
||||
@@ -118,21 +113,3 @@ oidnotin(PG_FUNCTION_ARGS)
|
||||
/* XXX assume oid maps to int4 */
|
||||
return int4notin(fcinfo);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX
|
||||
* If varattno (in parser/catalog_utils.h) ever is added to
|
||||
* cinterface.a, this routine should go away
|
||||
*/
|
||||
static int
|
||||
my_varattno(Relation rd, char *a)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rd->rd_rel->relnatts; i++)
|
||||
{
|
||||
if (namestrcmp(&rd->rd_att->attrs[i]->attname, a) == 0)
|
||||
return i + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
37
src/backend/utils/cache/lsyscache.c
vendored
37
src/backend/utils/cache/lsyscache.c
vendored
@@ -7,7 +7,7 @@
|
||||
* Portions Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.76 2002/07/12 18:43:18 tgl Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/lsyscache.c,v 1.77 2002/08/02 18:15:08 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Eventually, the index information should go through here, too.
|
||||
@@ -115,16 +115,15 @@ get_attname(Oid relid, AttrNumber attnum)
|
||||
*
|
||||
* Given the relation id and the attribute name,
|
||||
* return the "attnum" field from the attribute relation.
|
||||
*
|
||||
* Returns InvalidAttrNumber if the attr doesn't exist (or is dropped).
|
||||
*/
|
||||
AttrNumber
|
||||
get_attnum(Oid relid, char *attname)
|
||||
get_attnum(Oid relid, const char *attname)
|
||||
{
|
||||
HeapTuple tp;
|
||||
|
||||
tp = SearchSysCache(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(attname),
|
||||
0, 0);
|
||||
tp = SearchSysCacheAttName(relid, attname);
|
||||
if (HeapTupleIsValid(tp))
|
||||
{
|
||||
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
@@ -166,32 +165,6 @@ get_atttype(Oid relid, AttrNumber attnum)
|
||||
return InvalidOid;
|
||||
}
|
||||
|
||||
/* This routine uses the attname instead of the attnum because it
|
||||
* replaces the routine find_atttype, which is called sometimes when
|
||||
* only the attname, not the attno, is available.
|
||||
*/
|
||||
bool
|
||||
get_attisset(Oid relid, char *attname)
|
||||
{
|
||||
HeapTuple tp;
|
||||
|
||||
tp = SearchSysCache(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
PointerGetDatum(attname),
|
||||
0, 0);
|
||||
if (HeapTupleIsValid(tp))
|
||||
{
|
||||
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
bool result;
|
||||
|
||||
result = att_tup->attisset;
|
||||
ReleaseSysCache(tp);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_atttypmod
|
||||
*
|
||||
|
||||
67
src/backend/utils/cache/syscache.c
vendored
67
src/backend/utils/cache/syscache.c
vendored
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.84 2002/07/25 10:07:12 ishii Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/utils/cache/syscache.c,v 1.85 2002/08/02 18:15:08 tgl Exp $
|
||||
*
|
||||
* NOTES
|
||||
* These routines allow the parser/planner/executor to perform
|
||||
@@ -622,6 +622,71 @@ GetSysCacheOid(int cacheId,
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SearchSysCacheAttName
|
||||
*
|
||||
* This routine is equivalent to SearchSysCache on the ATTNAME cache,
|
||||
* except that it will return NULL if the found attribute is marked
|
||||
* attisdropped. This is convenient for callers that want to act as
|
||||
* though dropped attributes don't exist.
|
||||
*/
|
||||
HeapTuple
|
||||
SearchSysCacheAttName(Oid relid, const char *attname)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCache(ATTNAME,
|
||||
ObjectIdGetDatum(relid),
|
||||
CStringGetDatum(attname),
|
||||
0, 0);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return NULL;
|
||||
if (((Form_pg_attribute) GETSTRUCT(tuple))->attisdropped)
|
||||
{
|
||||
ReleaseSysCache(tuple);
|
||||
return NULL;
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
/*
|
||||
* SearchSysCacheCopyAttName
|
||||
*
|
||||
* As above, an attisdropped-aware version of SearchSysCacheCopy.
|
||||
*/
|
||||
HeapTuple
|
||||
SearchSysCacheCopyAttName(Oid relid, const char *attname)
|
||||
{
|
||||
HeapTuple tuple,
|
||||
newtuple;
|
||||
|
||||
tuple = SearchSysCacheAttName(relid, attname);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return tuple;
|
||||
newtuple = heap_copytuple(tuple);
|
||||
ReleaseSysCache(tuple);
|
||||
return newtuple;
|
||||
}
|
||||
|
||||
/*
|
||||
* SearchSysCacheExistsAttName
|
||||
*
|
||||
* As above, an attisdropped-aware version of SearchSysCacheExists.
|
||||
*/
|
||||
bool
|
||||
SearchSysCacheExistsAttName(Oid relid, const char *attname)
|
||||
{
|
||||
HeapTuple tuple;
|
||||
|
||||
tuple = SearchSysCacheAttName(relid, attname);
|
||||
if (!HeapTupleIsValid(tuple))
|
||||
return false;
|
||||
ReleaseSysCache(tuple);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* SysCacheGetAttr
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user