diff --git a/src/client/src/tscSQLParser.c b/src/client/src/tscSQLParser.c index 372e81d737..9c6ec39d35 100644 --- a/src/client/src/tscSQLParser.c +++ b/src/client/src/tscSQLParser.c @@ -4380,9 +4380,10 @@ int32_t setAlterTableInfo(SSqlObj* pSql, struct SSqlInfo* pInfo) { return TSDB_CODE_TSC_INVALID_SQL; } - if (index.columnIndex < tscGetNumOfColumns(pTableMeta)) { + int32_t numOfCols = tscGetNumOfColumns(pTableMeta); + if (index.columnIndex < numOfCols) { return invalidSqlErrMsg(pQueryInfo->msg, msg10); - } else if (index.columnIndex == 0) { + } else if (index.columnIndex == numOfCols) { return invalidSqlErrMsg(pQueryInfo->msg, msg11); }