mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Refactor typenameTypeId()
Split the old typenameTypeId() into two functions: A new typenameTypeId() that returns only a type OID, and typenameTypeIdAndMod() that returns type OID and typmod. This isolates call sites better that actually care about the typmod.
This commit is contained in:
@@ -159,8 +159,8 @@ transformExpr(ParseState *pstate, Node *expr)
|
||||
Oid elementType;
|
||||
int32 targetTypmod;
|
||||
|
||||
targetType = typenameTypeId(pstate, tc->typeName,
|
||||
&targetTypmod);
|
||||
typenameTypeIdAndMod(pstate, tc->typeName,
|
||||
&targetType, &targetTypmod);
|
||||
/*
|
||||
* If target is a domain over array, work with the base
|
||||
* array type here. transformTypeCast below will cast the
|
||||
@@ -1031,7 +1031,7 @@ transformAExprOf(ParseState *pstate, A_Expr *a)
|
||||
ltype = exprType(lexpr);
|
||||
foreach(telem, (List *) a->rexpr)
|
||||
{
|
||||
rtype = typenameTypeId(pstate, lfirst(telem), NULL);
|
||||
rtype = typenameTypeId(pstate, lfirst(telem));
|
||||
matched = (rtype == ltype);
|
||||
if (matched)
|
||||
break;
|
||||
@@ -1889,7 +1889,7 @@ transformXmlSerialize(ParseState *pstate, XmlSerialize *xs)
|
||||
XMLOID,
|
||||
"XMLSERIALIZE"));
|
||||
|
||||
targetType = typenameTypeId(pstate, xs->typeName, &targetTypmod);
|
||||
typenameTypeIdAndMod(pstate, xs->typeName, &targetType, &targetTypmod);
|
||||
|
||||
xexpr->xmloption = xs->xmloption;
|
||||
xexpr->location = xs->location;
|
||||
@@ -2052,7 +2052,7 @@ transformTypeCast(ParseState *pstate, TypeCast *tc)
|
||||
int32 targetTypmod;
|
||||
int location;
|
||||
|
||||
targetType = typenameTypeId(pstate, tc->typeName, &targetTypmod);
|
||||
typenameTypeIdAndMod(pstate, tc->typeName, &targetType, &targetTypmod);
|
||||
|
||||
if (inputType == InvalidOid)
|
||||
return expr; /* do nothing if NULL input */
|
||||
|
@@ -148,12 +148,12 @@ LookupOperNameTypeNames(ParseState *pstate, List *opername,
|
||||
if (oprleft == NULL)
|
||||
leftoid = InvalidOid;
|
||||
else
|
||||
leftoid = typenameTypeId(pstate, oprleft, NULL);
|
||||
leftoid = typenameTypeId(pstate, oprleft);
|
||||
|
||||
if (oprright == NULL)
|
||||
rightoid = InvalidOid;
|
||||
else
|
||||
rightoid = typenameTypeId(pstate, oprright, NULL);
|
||||
rightoid = typenameTypeId(pstate, oprright);
|
||||
|
||||
return LookupOperName(pstate, opername, leftoid, rightoid,
|
||||
noError, location);
|
||||
|
@@ -1165,7 +1165,7 @@ addRangeTableEntryForFunction(ParseState *pstate,
|
||||
errmsg("column \"%s\" cannot be declared SETOF",
|
||||
attrname),
|
||||
parser_errposition(pstate, n->typeName->location)));
|
||||
attrtype = typenameTypeId(pstate, n->typeName, &attrtypmod);
|
||||
typenameTypeIdAndMod(pstate, n->typeName, &attrtype, &attrtypmod);
|
||||
eref->colnames = lappend(eref->colnames, makeString(attrname));
|
||||
rte->funccoltypes = lappend_oid(rte->funccoltypes, attrtype);
|
||||
rte->funccoltypmods = lappend_int(rte->funccoltypmods, attrtypmod);
|
||||
|
@@ -206,24 +206,41 @@ typenameType(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
|
||||
}
|
||||
|
||||
/*
|
||||
* typenameTypeId - given a TypeName, return the type's OID and typmod
|
||||
* typenameTypeId - given a TypeName, return the type's OID
|
||||
*
|
||||
* This is equivalent to typenameType, but we only hand back the type OID
|
||||
* This is similar to typenameType, but we only hand back the type OID
|
||||
* not the syscache entry.
|
||||
*/
|
||||
Oid
|
||||
typenameTypeId(ParseState *pstate, const TypeName *typeName, int32 *typmod_p)
|
||||
typenameTypeId(ParseState *pstate, const TypeName *typeName)
|
||||
{
|
||||
Oid typoid;
|
||||
Type tup;
|
||||
|
||||
tup = typenameType(pstate, typeName, typmod_p);
|
||||
tup = typenameType(pstate, typeName, NULL);
|
||||
typoid = HeapTupleGetOid(tup);
|
||||
ReleaseSysCache(tup);
|
||||
|
||||
return typoid;
|
||||
}
|
||||
|
||||
/*
|
||||
* typenameTypeIdAndMod - given a TypeName, return the type's OID and typmod
|
||||
*
|
||||
* This is equivalent to typenameType, but we only hand back the type OID
|
||||
* and typmod, not the syscache entry.
|
||||
*/
|
||||
void
|
||||
typenameTypeIdAndMod(ParseState *pstate, const TypeName *typeName,
|
||||
Oid *typeid_p, int32 *typmod_p)
|
||||
{
|
||||
Type tup;
|
||||
|
||||
tup = typenameType(pstate, typeName, typmod_p);
|
||||
*typeid_p = HeapTupleGetOid(tup);
|
||||
ReleaseSysCache(tup);
|
||||
}
|
||||
|
||||
/*
|
||||
* typenameTypeMod - given a TypeName, return the internal typmod value
|
||||
*
|
||||
@@ -561,7 +578,7 @@ pts_error_callback(void *arg)
|
||||
* the string and convert it to a type OID and type modifier.
|
||||
*/
|
||||
void
|
||||
parseTypeString(const char *str, Oid *type_id, int32 *typmod_p)
|
||||
parseTypeString(const char *str, Oid *typeid_p, int32 *typmod_p)
|
||||
{
|
||||
StringInfoData buf;
|
||||
List *raw_parsetree_list;
|
||||
@@ -635,7 +652,7 @@ parseTypeString(const char *str, Oid *type_id, int32 *typmod_p)
|
||||
if (typeName->setof)
|
||||
goto fail;
|
||||
|
||||
*type_id = typenameTypeId(NULL, typeName, typmod_p);
|
||||
typenameTypeIdAndMod(NULL, typeName, typeid_p, typmod_p);
|
||||
|
||||
pfree(buf.data);
|
||||
|
||||
|
Reference in New Issue
Block a user