ATExecDropNotNull(Relation rel, const char *colName, LOCKMODE lockmode)
{
HeapTuple tuple;
+ Form_pg_attribute attTup;
AttrNumber attnum;
Relation attr_rel;
List *indexoidlist;
attr_rel = heap_open(AttributeRelationId, RowExclusiveLock);
tuple = SearchSysCacheCopyAttName(RelationGetRelid(rel), colName);
-
if (!HeapTupleIsValid(tuple))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_COLUMN),
errmsg("column \"%s\" of relation \"%s\" does not exist",
colName, RelationGetRelationName(rel))));
-
- attnum = ((Form_pg_attribute) GETSTRUCT(tuple))->attnum;
+ attTup = (Form_pg_attribute) GETSTRUCT(tuple);
+ attnum = attTup->attnum;
/* Prevent them from altering a system attribute */
if (attnum <= 0)
errmsg("cannot alter system column \"%s\"",
colName)));
- if (get_attidentity(RelationGetRelid(rel), attnum))
+ if (attTup->attidentity)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("column \"%s\" of relation \"%s\" is an identity column",
/*
* Okay, actually perform the catalog change ... if needed
*/
- if (((Form_pg_attribute) GETSTRUCT(tuple))->attnotnull)
+ if (attTup->attnotnull)
{
- ((Form_pg_attribute) GETSTRUCT(tuple))->attnotnull = false;
+ attTup->attnotnull = false;
CatalogTupleUpdate(attr_rel, &tuple->t_self, tuple);
ATExecColumnDefault(Relation rel, const char *colName,
Node *newDefault, LOCKMODE lockmode)
{
+ TupleDesc tupdesc = RelationGetDescr(rel);
AttrNumber attnum;
ObjectAddress address;
errmsg("cannot alter system column \"%s\"",
colName)));
- if (get_attidentity(RelationGetRelid(rel), attnum))
+ if (TupleDescAttr(tupdesc, attnum - 1)->attidentity)
ereport(ERROR,
(errcode(ERRCODE_SYNTAX_ERROR),
errmsg("column \"%s\" of relation \"%s\" is an identity column",
const char *queryString)
{
Relation rel;
+ TupleDesc tupdesc;
ParseState *pstate;
CreateStmtContext cxt;
List *result;
/* Caller is responsible for locking the relation */
rel = relation_open(relid, NoLock);
+ tupdesc = RelationGetDescr(rel);
/* Set up pstate */
pstate = make_parsestate(NULL);
* if attribute not found, something will error about it
* later
*/
- if (attnum != InvalidAttrNumber && get_attidentity(relid, attnum))
+ if (attnum != InvalidAttrNumber &&
+ TupleDescAttr(tupdesc, attnum - 1)->attidentity)
{
Oid seq_relid = getOwnedSequence(relid, attnum);
Oid typeOid = typenameTypeId(pstate, def->typeName);
return InvalidAttrNumber;
}
-/*
- * get_attidentity
- *
- * Given the relation id and the attribute name,
- * return the "attidentity" field from the attribute relation.
- *
- * Returns '\0' if not found.
- *
- * Since no identity is represented by '\0', this can also be used as a
- * Boolean test.
- */
-char
-get_attidentity(Oid relid, AttrNumber attnum)
-{
- HeapTuple tp;
-
- tp = SearchSysCache2(ATTNUM,
- ObjectIdGetDatum(relid),
- Int16GetDatum(attnum));
- if (HeapTupleIsValid(tp))
- {
- Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
- char result;
-
- result = att_tup->attidentity;
- ReleaseSysCache(tp);
- return result;
- }
- else
- return '\0';
-}
-
/*
* get_atttype
*
int16 procnum);
extern char *get_attname(Oid relid, AttrNumber attnum, bool missing_ok);
extern AttrNumber get_attnum(Oid relid, const char *attname);
-extern char get_attidentity(Oid relid, AttrNumber attnum);
extern Oid get_atttype(Oid relid, AttrNumber attnum);
extern void get_atttypetypmodcoll(Oid relid, AttrNumber attnum,
Oid *typid, int32 *typmod, Oid *collid);