mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
get_relid_attribute_name is dead, long live get_attname
The modern way is to use a missing_ok argument instead of two separate almost-identical routines, so do that. Author: Michaël Paquier Reviewed-by: Álvaro Herrera Discussion: https://postgr.es/m/20180201063212.GE6398@paquier.xyz
This commit is contained in:
31
src/backend/utils/cache/lsyscache.c
vendored
31
src/backend/utils/cache/lsyscache.c
vendored
@ -765,19 +765,19 @@ get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
|
||||
|
||||
/*
|
||||
* get_attname
|
||||
* Given the relation id and the attribute number,
|
||||
* return the "attname" field from the attribute relation.
|
||||
* Given the relation id and the attribute number, return the "attname"
|
||||
* field from the attribute relation as a palloc'ed string.
|
||||
*
|
||||
* Note: returns a palloc'd copy of the string, or NULL if no such attribute.
|
||||
* If no such attribute exists and missing_ok is true, NULL is returned;
|
||||
* otherwise a not-intended-for-user-consumption error is thrown.
|
||||
*/
|
||||
char *
|
||||
get_attname(Oid relid, AttrNumber attnum)
|
||||
get_attname(Oid relid, AttrNumber attnum, bool missing_ok)
|
||||
{
|
||||
HeapTuple tp;
|
||||
|
||||
tp = SearchSysCache2(ATTNUM,
|
||||
ObjectIdGetDatum(relid),
|
||||
Int16GetDatum(attnum));
|
||||
ObjectIdGetDatum(relid), Int16GetDatum(attnum));
|
||||
if (HeapTupleIsValid(tp))
|
||||
{
|
||||
Form_pg_attribute att_tup = (Form_pg_attribute) GETSTRUCT(tp);
|
||||
@ -787,26 +787,11 @@ get_attname(Oid relid, AttrNumber attnum)
|
||||
ReleaseSysCache(tp);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* get_relid_attribute_name
|
||||
*
|
||||
* Same as above routine get_attname(), except that error
|
||||
* is handled by elog() instead of returning NULL.
|
||||
*/
|
||||
char *
|
||||
get_relid_attribute_name(Oid relid, AttrNumber attnum)
|
||||
{
|
||||
char *attname;
|
||||
|
||||
attname = get_attname(relid, attnum);
|
||||
if (attname == NULL)
|
||||
if (!missing_ok)
|
||||
elog(ERROR, "cache lookup failed for attribute %d of relation %u",
|
||||
attnum, relid);
|
||||
return attname;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user