Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8237f27

Browse files
committed
get_relid_attribute_name is dead, long live get_attname
The modern way is to use a missing_ok argument instead of two separatealmost-identical routines, so do that.Author: Michaël PaquierReviewed-by: Álvaro HerreraDiscussion:https://postgr.es/m/20180201063212.GE6398@paquier.xyz
1 parent88ef48c commit8237f27

File tree

11 files changed

+40
-55
lines changed

11 files changed

+40
-55
lines changed

‎contrib/postgres_fdw/deparse.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2176,7 +2176,7 @@ deparseColumnRef(StringInfo buf, int varno, int varattno, PlannerInfo *root,
21762176
* FDW option, use attribute name.
21772177
*/
21782178
if (colname==NULL)
2179-
colname=get_relid_attribute_name(rte->relid,varattno);
2179+
colname=get_attname(rte->relid,varattno, false);
21802180

21812181
if (qualify_col)
21822182
ADD_REL_QUALIFIER(buf,varno);

‎contrib/postgres_fdw/postgres_fdw.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5545,7 +5545,7 @@ conversion_error_callback(void *arg)
55455545
if (var->varattno==0)
55465546
is_wholerow= true;
55475547
else
5548-
attname=get_relid_attribute_name(rte->relid,var->varattno);
5548+
attname=get_attname(rte->relid,var->varattno, false);
55495549

55505550
relname=get_rel_name(rte->relid);
55515551
}

‎contrib/sepgsql/dml.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ fixup_inherited_columns(Oid parentId, Oid childId, Bitmapset *columns)
118118
continue;
119119
}
120120

121-
attname=get_attname(parentId,attno);
122-
if (!attname)
123-
elog(ERROR,"cache lookup failed for attribute %d of relation %u",
124-
attno,parentId);
121+
attname=get_attname(parentId,attno, false);
125122
attno=get_attnum(childId,attname);
126123
if (attno==InvalidAttrNumber)
127124
elog(ERROR,"cache lookup failed for attribute %s of relation %u",

‎src/backend/catalog/heap.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2405,7 +2405,8 @@ AddRelationNewConstraints(Relation rel,
24052405

24062406
if (list_length(vars)==1)
24072407
colname=get_attname(RelationGetRelid(rel),
2408-
((Var*)linitial(vars))->varattno);
2408+
((Var*)linitial(vars))->varattno,
2409+
true);
24092410
else
24102411
colname=NULL;
24112412

‎src/backend/catalog/objectaddress.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2682,8 +2682,9 @@ getObjectDescription(const ObjectAddress *object)
26822682
getRelationDescription(&buffer,object->objectId);
26832683
if (object->objectSubId!=0)
26842684
appendStringInfo(&buffer,_(" column %s"),
2685-
get_relid_attribute_name(object->objectId,
2686-
object->objectSubId));
2685+
get_attname(object->objectId,
2686+
object->objectSubId,
2687+
false));
26872688
break;
26882689

26892690
caseOCLASS_PROC:
@@ -4103,8 +4104,8 @@ getObjectIdentityParts(const ObjectAddress *object,
41034104
{
41044105
char*attr;
41054106

4106-
attr=get_relid_attribute_name(object->objectId,
4107-
object->objectSubId);
4107+
attr=get_attname(object->objectId,object->objectSubId,
4108+
false);
41084109
appendStringInfo(&buffer,".%s",quote_identifier(attr));
41094110
if (objname)
41104111
*objname=lappend(*objname,attr);

‎src/backend/parser/parse_relation.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2687,7 +2687,7 @@ get_rte_attribute_name(RangeTblEntry *rte, AttrNumber attnum)
26872687
* built (which can easily happen for rules).
26882688
*/
26892689
if (rte->rtekind==RTE_RELATION)
2690-
returnget_relid_attribute_name(rte->relid,attnum);
2690+
returnget_attname(rte->relid,attnum, false);
26912691

26922692
/*
26932693
* Otherwise use the column name from eref. There should always be one.

‎src/backend/parser/parse_utilcmd.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1470,7 +1470,7 @@ generateClonedIndexStmt(RangeVar *heapRel, Oid heapRelid, Relation source_idx,
14701470
/* Simple index column */
14711471
char*attname;
14721472

1473-
attname=get_relid_attribute_name(indrelid,attnum);
1473+
attname=get_attname(indrelid,attnum, false);
14741474
keycoltype=get_atttype(indrelid,attnum);
14751475

14761476
iparam->name=attname;
@@ -3406,8 +3406,8 @@ transformPartitionBound(ParseState *pstate, Relation parent,
34063406

34073407
/* Get the only column's name in case we need to output an error */
34083408
if (key->partattrs[0]!=0)
3409-
colname=get_relid_attribute_name(RelationGetRelid(parent),
3410-
key->partattrs[0]);
3409+
colname=get_attname(RelationGetRelid(parent),
3410+
key->partattrs[0], false);
34113411
else
34123412
colname=deparse_expression((Node*)linitial(partexprs),
34133413
deparse_context_for(RelationGetRelationName(parent),
@@ -3491,8 +3491,8 @@ transformPartitionBound(ParseState *pstate, Relation parent,
34913491

34923492
/* Get the column's name in case we need to output an error */
34933493
if (key->partattrs[i]!=0)
3494-
colname=get_relid_attribute_name(RelationGetRelid(parent),
3495-
key->partattrs[i]);
3494+
colname=get_attname(RelationGetRelid(parent),
3495+
key->partattrs[i], false);
34963496
else
34973497
{
34983498
colname=deparse_expression((Node*)list_nth(partexprs,j),

‎src/backend/utils/adt/ruleutils.c

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,8 @@ pg_get_triggerdef_worker(Oid trigid, bool pretty)
908908

909909
if (i>0)
910910
appendStringInfoString(&buf,", ");
911-
attname=get_relid_attribute_name(trigrec->tgrelid,
912-
trigrec->tgattr.values[i]);
911+
attname=get_attname(trigrec->tgrelid,
912+
trigrec->tgattr.values[i], false);
913913
appendStringInfoString(&buf,quote_identifier(attname));
914914
}
915915
}
@@ -1292,7 +1292,7 @@ pg_get_indexdef_worker(Oid indexrelid, int colno,
12921292
char*attname;
12931293
int32keycoltypmod;
12941294

1295-
attname=get_relid_attribute_name(indrelid,attnum);
1295+
attname=get_attname(indrelid,attnum, false);
12961296
if (!colno||colno==keyno+1)
12971297
appendStringInfoString(&buf,quote_identifier(attname));
12981298
get_atttypetypmodcoll(indrelid,attnum,
@@ -1535,7 +1535,7 @@ pg_get_statisticsobj_worker(Oid statextid, bool missing_ok)
15351535
if (colno>0)
15361536
appendStringInfoString(&buf,", ");
15371537

1538-
attname=get_relid_attribute_name(statextrec->stxrelid,attnum);
1538+
attname=get_attname(statextrec->stxrelid,attnum, false);
15391539

15401540
appendStringInfoString(&buf,quote_identifier(attname));
15411541
}
@@ -1692,7 +1692,7 @@ pg_get_partkeydef_worker(Oid relid, int prettyFlags,
16921692
char*attname;
16931693
int32keycoltypmod;
16941694

1695-
attname=get_relid_attribute_name(relid,attnum);
1695+
attname=get_attname(relid,attnum, false);
16961696
appendStringInfoString(&buf,quote_identifier(attname));
16971697
get_atttypetypmodcoll(relid,attnum,
16981698
&keycoltype,&keycoltypmod,
@@ -2196,7 +2196,7 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
21962196
{
21972197
char*colName;
21982198

2199-
colName=get_relid_attribute_name(relId,DatumGetInt16(keys[j]));
2199+
colName=get_attname(relId,DatumGetInt16(keys[j]), false);
22002200

22012201
if (j==0)
22022202
appendStringInfoString(buf,quote_identifier(colName));
@@ -6015,8 +6015,9 @@ get_insert_query_def(Query *query, deparse_context *context)
60156015
* tle->resname, since resname will fail to track RENAME.
60166016
*/
60176017
appendStringInfoString(buf,
6018-
quote_identifier(get_relid_attribute_name(rte->relid,
6019-
tle->resno)));
6018+
quote_identifier(get_attname(rte->relid,
6019+
tle->resno,
6020+
false)));
60206021

60216022
/*
60226023
* Print any indirection needed (subfields or subscripts), and strip
@@ -6319,8 +6320,9 @@ get_update_query_targetlist_def(Query *query, List *targetList,
63196320
* tle->resname, since resname will fail to track RENAME.
63206321
*/
63216322
appendStringInfoString(buf,
6322-
quote_identifier(get_relid_attribute_name(rte->relid,
6323-
tle->resno)));
6323+
quote_identifier(get_attname(rte->relid,
6324+
tle->resno,
6325+
false)));
63246326

63256327
/*
63266328
* Print any indirection needed (subfields or subscripts), and strip
@@ -10340,8 +10342,8 @@ processIndirection(Node *node, deparse_context *context)
1034010342
* target lists, but this function cannot be used for that case.
1034110343
*/
1034210344
Assert(list_length(fstore->fieldnums)==1);
10343-
fieldname=get_relid_attribute_name(typrelid,
10344-
linitial_int(fstore->fieldnums));
10345+
fieldname=get_attname(typrelid,
10346+
linitial_int(fstore->fieldnums), false);
1034510347
appendStringInfo(buf,".%s",quote_identifier(fieldname));
1034610348

1034710349
/*

‎src/backend/utils/cache/lsyscache.c

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -765,19 +765,19 @@ get_opfamily_proc(Oid opfamily, Oid lefttype, Oid righttype, int16 procnum)
765765

766766
/*
767767
* get_attname
768-
*Given the relation id and the attribute number,
769-
*return the "attname"field from the attribute relation.
768+
*Given the relation id and the attribute number, return the "attname"
769+
*field from the attribute relation as a palloc'ed string.
770770
*
771-
* Note: returns a palloc'd copy of the string, or NULL if no such attribute.
771+
* If no such attribute exists and missing_ok is true, NULL is returned;
772+
* otherwise a not-intended-for-user-consumption error is thrown.
772773
*/
773774
char*
774-
get_attname(Oidrelid,AttrNumberattnum)
775+
get_attname(Oidrelid,AttrNumberattnum,boolmissing_ok)
775776
{
776777
HeapTupletp;
777778

778779
tp=SearchSysCache2(ATTNUM,
779-
ObjectIdGetDatum(relid),
780-
Int16GetDatum(attnum));
780+
ObjectIdGetDatum(relid),Int16GetDatum(attnum));
781781
if (HeapTupleIsValid(tp))
782782
{
783783
Form_pg_attributeatt_tup= (Form_pg_attribute)GETSTRUCT(tp);
@@ -787,26 +787,11 @@ get_attname(Oid relid, AttrNumber attnum)
787787
ReleaseSysCache(tp);
788788
returnresult;
789789
}
790-
else
791-
returnNULL;
792-
}
793-
794-
/*
795-
* get_relid_attribute_name
796-
*
797-
* Same as above routine get_attname(), except that error
798-
* is handled by elog() instead of returning NULL.
799-
*/
800-
char*
801-
get_relid_attribute_name(Oidrelid,AttrNumberattnum)
802-
{
803-
char*attname;
804790

805-
attname=get_attname(relid,attnum);
806-
if (attname==NULL)
791+
if (!missing_ok)
807792
elog(ERROR,"cache lookup failed for attribute %d of relation %u",
808793
attnum,relid);
809-
returnattname;
794+
returnNULL;
810795
}
811796

812797
/*

‎src/backend/utils/cache/relcache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5250,7 +5250,7 @@ errtablecol(Relation rel, int attnum)
52505250
if (attnum>0&&attnum <=reldesc->natts)
52515251
colname=NameStr(TupleDescAttr(reldesc,attnum-1)->attname);
52525252
else
5253-
colname=get_relid_attribute_name(RelationGetRelid(rel),attnum);
5253+
colname=get_attname(RelationGetRelid(rel),attnum, false);
52545254

52555255
returnerrtablecolname(rel,colname);
52565256
}

‎src/include/utils/lsyscache.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ extern List *get_op_btree_interpretation(Oid opno);
8383
externboolequality_ops_are_compatible(Oidopno1,Oidopno2);
8484
externOidget_opfamily_proc(Oidopfamily,Oidlefttype,Oidrighttype,
8585
int16procnum);
86-
externchar*get_attname(Oidrelid,AttrNumberattnum);
87-
externchar*get_relid_attribute_name(Oidrelid,AttrNumberattnum);
86+
externchar*get_attname(Oidrelid,AttrNumberattnum,boolmissing_ok);
8887
externAttrNumberget_attnum(Oidrelid,constchar*attname);
8988
externcharget_attidentity(Oidrelid,AttrNumberattnum);
9089
externOidget_atttype(Oidrelid,AttrNumberattnum);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp