{"record":{"id":"88f2da2d8a5f233b","repo":"prestodb/presto","slug":"type-mismatch-88f2da","errorCode":"TYPE_MISMATCH","errorMessage":"Type %s is invalid. Supported table version AS OF/BEFORE expression type is Timestamp or Timestamp with Time Zone.","messagePattern":"Type (.+?) is invalid\\. Supported table version AS OF/BEFORE expression type is Timestamp or Timestamp with Time Zone\\.","errorType":"error_code","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/execution/CreateBranchTask.java","lineNumber":108,"sourceCode":"        if (statement.getTableVersion().isPresent()) {\n            TableVersionExpression tableVersionExpr = statement.getTableVersion().get();\n            Expression stateExpr = tableVersionExpr.getStateExpression();\n            TableVersionExpression.TableVersionType tableVersionType = tableVersionExpr.getTableVersionType();\n            TableVersionExpression.TableVersionOperator tableVersionOperator = tableVersionExpr.getTableVersionOperator();\n\n            Map<NodeRef<Parameter>, Expression> parameterLookup = parameterExtractor(statement, parameters);\n\n            ExpressionAnalyzer analyzer = ExpressionAnalyzer.createConstantAnalyzer(\n                    metadata.getFunctionAndTypeManager().getFunctionAndTypeResolver(),\n                    session,\n                    parameterLookup,\n                    WarningCollector.NOOP);\n            analyzer.analyze(stateExpr, Scope.create());\n            Type stateExprType = analyzer.getExpressionTypes().get(NodeRef.of(stateExpr));\n\n            if (tableVersionType == TIMESTAMP) {\n                if (!(stateExprType instanceof TimestampWithTimeZoneType || stateExprType instanceof TimestampType)) {\n                    throw new SemanticException(TYPE_MISMATCH, stateExpr,\n                            \"Type %s is invalid. Supported table version AS OF/BEFORE expression type is Timestamp or Timestamp with Time Zone.\",\n                            stateExprType.getDisplayName());\n                }\n            }\n            else if (tableVersionType == VERSION) {\n                if (!(stateExprType instanceof BigintType || stateExprType instanceof VarcharType)) {\n                    throw new SemanticException(TYPE_MISMATCH, stateExpr, \"Type %s is invalid. Supported table version AS OF/BEFORE expression type is BIGINT or VARCHAR\", stateExprType.getDisplayName());\n                }\n            }\n\n            Object evalStateExpr = evaluateConstantExpression(stateExpr, stateExprType, metadata, session, parameterLookup);\n            VersionType versionType = tableVersionType == TIMESTAMP ? VersionType.TIMESTAMP : VersionType.VERSION;\n            VersionOperator versionOperator = tableVersionOperator == TableVersionExpression.TableVersionOperator.EQUAL\n                    ? VersionOperator.EQUAL : VersionOperator.LESS_THAN;\n\n            tableVersion = Optional.of(new ConnectorTableVersion(versionType, versionOperator, stateExprType, evalStateExpr));\n        }\n","sourceCodeStart":90,"sourceCodeEnd":126,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/execution/CreateBranchTask.java#L90-L126","documentation":"The AS OF/BEFORE version expression in CREATE BRANCH was declared as a TIMESTAMP version, but its analyzed expression type is neither TimestampType nor TimestampWithTimeZoneType. The analyzer computes the constant expression's type and throws SemanticException TYPE_MISMATCH when it doesn't match the required timestamp family.","triggerScenarios":"CREATE BRANCH ... FOR TIMESTAMP AS OF <expr> where <expr> evaluates to VARCHAR, BIGINT, DATE, or another non-timestamp type; forgetting a CAST on a string or date literal used as the timestamp.","commonSituations":"Passing a plain string '2024-01-01 00:00:00' without CAST(... AS TIMESTAMP); using current_date (DATE) instead of current_timestamp; refactored queries where a parameter's type changed.","solutions":["CAST the expression to TIMESTAMP or TIMESTAMP WITH TIME ZONE, e.g. FOR TIMESTAMP AS OF TIMESTAMP '2024-01-01 00:00:00'","Replace DATE expressions with current_timestamp or CAST(current_date AS TIMESTAMP)","Verify the analyzed type of the expression matches the declared version type (TIMESTAMP vs VERSION)","If a bigint/varchar snapshot id was intended, use FOR VERSION AS OF instead of FOR TIMESTAMP AS OF"],"exampleFix":"// before\nCREATE BRANCH b FROM t FOR TIMESTAMP AS OF '2024-01-01 00:00:00';\n// after\nCREATE BRANCH b FROM t FOR TIMESTAMP AS OF CAST('2024-01-01 00:00:00' AS TIMESTAMP);","handlingStrategy":"validation","validationCode":"// ensure the timestamp expr is a proper TIMESTAMP literal\nString tsExpr = \"CAST('\" + iso + \"' AS TIMESTAMP)\"; // not a raw string","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always CAST string/date expressions to TIMESTAMP in FOR TIMESTAMP AS OF","Use TIMESTAMP literals like TIMESTAMP '2024-01-01 00:00:00'","Use current_timestamp instead of current_date for timestamp clauses","Match the clause (TIMESTAMP vs VERSION) to the expression type"],"tags":["type-mismatch","timestamp","branching"],"backgroundTag":"type-mismatch","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}