mirror of
https://github.com/postgres/postgres.git
synced 2025-07-28 23:42:10 +03:00
Identity columns
This is the SQL standard-conforming variant of PostgreSQL's serial columns. It fixes a few usability issues that serial columns have: - CREATE TABLE / LIKE copies default but refers to same sequence - cannot add/drop serialness with ALTER TABLE - dropping default does not drop sequence - need to grant separate privileges to sequence - other slight weirdnesses because serial is some kind of special macro Reviewed-by: Vitaly Burovoy <vitaly.burovoy@gmail.com>
This commit is contained in:
32
src/backend/utils/cache/lsyscache.c
vendored
32
src/backend/utils/cache/lsyscache.c
vendored
@ -836,6 +836,38 @@ get_attnum(Oid relid, const char *attname)
|
||||
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
|
||||
*
|
||||
|
1
src/backend/utils/cache/relcache.c
vendored
1
src/backend/utils/cache/relcache.c
vendored
@ -3268,6 +3268,7 @@ RelationBuildLocalRelation(const char *relname,
|
||||
has_not_null = false;
|
||||
for (i = 0; i < natts; i++)
|
||||
{
|
||||
rel->rd_att->attrs[i]->attidentity = tupDesc->attrs[i]->attidentity;
|
||||
rel->rd_att->attrs[i]->attnotnull = tupDesc->attrs[i]->attnotnull;
|
||||
has_not_null |= tupDesc->attrs[i]->attnotnull;
|
||||
}
|
||||
|
Reference in New Issue
Block a user