解决创建函数时,定义参数的数据类型是序列整型,提示类型不存在的问题

在返回值和定义参数的数据类型判断时,增加对序列整型的判定
This commit is contained in:
徐鲲鹏
2020-09-01 11:37:41 +08:00
committed by Gitee
parent f370abbabd
commit 12a82b1e0d

View File

@ -105,11 +105,45 @@ static void compute_return_type(
Type typtup;
AclResult aclresult;
Oid typowner = InvalidOid;
bool isSerial = false;
/*
* isalter is true, change the owner of the objects as the owner of the
* namespace, if the owner of the namespce has the same name as the namescpe
*/
bool isalter = false;
/* Check for SERIAL pseudo-types */
isSerial = false;
if (returnType && list_length(returnType->names) == 1 && returnType->pct_type == false) {
char* typname = strVal(linitial(returnType->names));
if (strcmp(typname, "smallserial") == 0 || strcmp(typname, "serial2") == 0) {
isSerial = true;
returnType->names = NIL;
returnType->typeOid = INT2OID;
} else if (strcmp(typname, "serial") == 0 || strcmp(typname, "serial4") == 0) {
isSerial = true;
returnType->names = NIL;
returnType->typeOid = INT4OID;
} else if (strcmp(typname, "bigserial") == 0 || strcmp(typname, "serial8") == 0) {
isSerial = true;
returnType->names = NIL;
returnType->typeOid = INT8OID;
}
if (isSerial) {
/*
* We have to reject "serial[]" explicitly, because once we've set
* typeid, LookupTypeName won't notice arrayBounds. We don't need any
* special coding for serial(typmod) though.
*/
if (returnType->arrayBounds != NIL) {
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("array of serial is not implemented")));
}
}
}
typtup = LookupTypeName(NULL, returnType, NULL);
/*
@ -223,6 +257,7 @@ static void examine_parameter_list(List* parameters, Oid languageOid, const char
int outCount = 0;
int varCount = 0;
bool have_names = false;
bool isSerial = false;
ListCell* x = NULL;
int i;
ParseState* pstate = NULL;
@ -249,6 +284,39 @@ static void examine_parameter_list(List* parameters, Oid languageOid, const char
Type typtup;
AclResult aclresult;
/* Check for SERIAL pseudo-types */
isSerial = false;
if (t && list_length(t->names) == 1 && t->pct_type == false) {
char* typname = strVal(linitial(t->names));
if (strcmp(typname, "smallserial") == 0 || strcmp(typname, "serial2") == 0) {
isSerial = true;
t->names = NIL;
t->typeOid = INT2OID;
} else if (strcmp(typname, "serial") == 0 || strcmp(typname, "serial4") == 0) {
isSerial = true;
t->names = NIL;
t->typeOid = INT4OID;
} else if (strcmp(typname, "bigserial") == 0 || strcmp(typname, "serial8") == 0) {
isSerial = true;
t->names = NIL;
t->typeOid = INT8OID;
}
if (isSerial) {
/*
* We have to reject "serial[]" explicitly, because once we've set
* typeid, LookupTypeName won't notice arrayBounds. We don't need any
* special coding for serial(typmod) though.
*/
if (t->arrayBounds != NIL) {
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("array of serial is not implemented")));
}
}
}
typtup = LookupTypeName(NULL, t, NULL);
/*
* If the type is relation, then we check