From 12a82b1e0d9626e67070a1f2ff304efb06f2f82d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E9=B2=B2=E9=B9=8F?= Date: Tue, 1 Sep 2020 11:37:41 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3=E5=88=9B=E5=BB=BA=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E6=97=B6=EF=BC=8C=E5=AE=9A=E4=B9=89=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E7=B1=BB=E5=9E=8B=E6=98=AF=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E6=95=B4=E5=9E=8B=EF=BC=8C=E6=8F=90=E7=A4=BA=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E4=B8=8D=E5=AD=98=E5=9C=A8=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?=20=E5=9C=A8=E8=BF=94=E5=9B=9E=E5=80=BC=E5=92=8C=E5=AE=9A?= =?UTF-8?q?=E4=B9=89=E5=8F=82=E6=95=B0=E7=9A=84=E6=95=B0=E6=8D=AE=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E5=88=A4=E6=96=AD=E6=97=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=AF=B9=E5=BA=8F=E5=88=97=E6=95=B4=E5=9E=8B=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../optimizer/commands/functioncmds.cpp | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/src/gausskernel/optimizer/commands/functioncmds.cpp b/src/gausskernel/optimizer/commands/functioncmds.cpp index 5f37e8ab4..64e733612 100755 --- a/src/gausskernel/optimizer/commands/functioncmds.cpp +++ b/src/gausskernel/optimizer/commands/functioncmds.cpp @@ -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