{"record":{"id":"b49f4f219257df90","repo":"prestodb/presto","slug":"type-mismatch-b49f4f","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/CreateTagTask.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/CreateTagTask.java#L90-L126","documentation":"In CREATE TAG ... AS OF/BEFORE <expr>, the version type was TIMESTAMP but the AS OF/BEFORE expression analyzed to a type other than Timestamp or Timestamp with Time Zone. CreateTagTask.execute analyzes the state expression and enforces type compatibility with the declared table version type, raising TYPE_MISMATCH otherwise.","triggerScenarios":"tableVersionType == TIMESTAMP and stateExprType is e.g. VARCHAR, DATE, BIGINT, or TIMESTAMP(3) WITH TIME ZONE variants not matching TimestampType/TimestampWithTimeZoneType — e.g. CREATE TAG t AS OF '2024-01-01' (string literal) or AS OF DATE '2024-01-01'.","commonSituations":"Passing a quoted date string instead of a proper TIMESTAMP literal; using DATE or unix epoch numbers for a timestamp-versioned tag; dialect differences where string-to-timestamp implicit casts are allowed elsewhere.","solutions":["Cast the expression: CREATE TAG t AS OF TIMESTAMP '2024-01-01 00:00:00'.","Add a time zone for timestamp-with-time-zone support: AS OF TIMESTAMP '2024-01-01 00:00:00 UTC'.","Alternatively declare/use a VERSION (bigint or varchar) table version if the expression is an ID, and use the matching AS OF form."],"exampleFix":"// before\nCREATE TAG t AS OF '2024-01-01 00:00:00' TAG 'v1';\n// after\nCREATE TAG t AS OF TIMESTAMP '2024-01-01 00:00:00' TAG 'v1';","handlingStrategy":"validation","validationCode":"Type t = analyzer.getExpressionTypes().get(NodeRef.of(stateExpr));\nif (tableVersionType == TIMESTAMP &&\n    !(t instanceof TimestampWithTimeZoneType || t instanceof TimestampType)) {\n    throw new IllegalArgumentException(\"AS OF/BEFORE expression must be TIMESTAMP, got \" + t.getDisplayName());\n}","typeGuard":"boolean isTimestampLike(Type t) {\n    return t instanceof TimestampType || t instanceof TimestampWithTimeZoneType;\n}","tryCatchPattern":"try {\n    future = createTagTask.execute(statement, ...);\n} catch (SemanticException e) {\n    if (e.getCode() == TYPE_MISMATCH && e.getMessage().contains(\"table version\")) {\n        // rewrite with an explicit TIMESTAMP cast and retry\n    }\n}","preventionTips":["Always write table version expressions as explicit TIMESTAMP literals/casts.","Never pass bare strings, DATE, or epoch numbers to AS OF/BEFORE for timestamp versions.","Match the expression type to the table's version type (TIMESTAMP vs VERSION bigint/varchar)."],"tags":["presto","ddl","create-tag","type-mismatch","timestamp"],"backgroundTag":"timestamp-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"}