{"record":{"id":"eceb6c8c950d80d9","repo":"prestodb/presto","slug":"precision-not-supported","errorCode":null,"errorMessage":"Precision not supported ","messagePattern":"Precision not supported ","errorType":"exception","errorClass":"UnsupportedOperationException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/SqlTimestamp.java","lineNumber":136,"sourceCode":"        SqlTimestamp other = (SqlTimestamp) obj;\n        // The current semantics returns NOT equal for millis and micros timestamp,\n        // even though they represent the same time. (ex. same second, millis/micros set to 0).\n        return this.value == other.value &&\n                this.precision == other.precision &&\n                Objects.equals(this.sessionTimeZoneKey, other.sessionTimeZoneKey);\n    }\n\n    @JsonValue\n    @Override\n    public String toString()\n    {\n        if (precision == MILLISECONDS) {\n            return formatInstant(millisToInstant(value), JSON_MILLIS_FORMATTER);\n        }\n        if (precision == MICROSECONDS) {\n            return formatInstant(microsToInstant(value), JSON_MICROS_FORMATTER);\n        }\n        throw new UnsupportedOperationException(\"Precision not supported \" + precision);\n    }\n\n    private String formatInstant(Instant instant, DateTimeFormatter formatter)\n    {\n        if (isLegacyTimestamp()) {\n            return instant.atZone(ZoneId.of(sessionTimeZoneKey.get().getId())).format(formatter);\n        }\n        else {\n            return instant.atZone(ZoneId.of(UTC_KEY.getId())).format(formatter);\n        }\n    }\n\n    private static TimeUnit validatePrecision(TimeUnit precision)\n    {\n        requireNonNull(precision, \"precision\");\n        if (precision == MILLISECONDS || precision == MICROSECONDS) {\n            return precision;\n        }","sourceCodeStart":118,"sourceCodeEnd":154,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/SqlTimestamp.java#L118-L154","documentation":"SqlTimestamp.toString (renderer used by getTimestampLiteralAsString and toSqlTimestampString) only supports MILLISECONDS and MICROSECONDS precisions; any other precision throws UnsupportedOperationException(\"Precision not supported \" + precision). It indicates a SqlTimestamp instance was built with an unexpected TimeUnit precision.","triggerScenarios":"Calling toString/getTimestampLiteralAsString/toSqlTimestampString on a SqlTimestamp whose precision TimeUnit is not MILLISECONDS or MICROSECONDS.","commonSituations":"Custom type systems mapping precision beyond micros (e.g. nanoseconds) into SqlTimestamp; version drift where a new precision was introduced elsewhere but not in formatting; test harnesses constructing SqlTimestamp with SECONDS/NANOSECONDS.","solutions":["Construct SqlTimestamp only with TimeUnit.MILLISECONDS or TimeUnit.MICROSECONDS (use SqlTimestamp.newInstance with a supported precision).","Convert nanosecond-precision values down to micros before wrapping in SqlTimestamp.","If you need nanos, use the higher-precision type (e.g. LongTimestamp/LongTimestampWithTimeZone) instead of SqlTimestamp."],"exampleFix":"// before\nSqlTimestamp ts = new SqlTimestamp(epochValue, TimeUnit.NANOSECONDS, sessionKey);\nts.toString();\n// after\nSqlTimestamp ts = new SqlTimestamp(epochMicros, TimeUnit.MICROSECONDS, sessionKey);","handlingStrategy":"type-guard","validationCode":"if (precision != TimeUnit.MILLISECONDS && precision != TimeUnit.MICROSECONDS) { /* convert precision first */ }","typeGuard":"boolean hasSupportedPrecision(SqlTimestamp ts) { ts.getPrecision() == TimeUnit.MILLISECONDS || ts.getPrecision() == TimeUnit.MICROSECONDS; }","tryCatchPattern":"try { ts.toString(); } catch (UnsupportedOperationException e) { /* re-create with MILLISECONDS/MICROSECONDS precision */ }","preventionTips":["Construct SqlTimestamp only with millis/micros precision.","Down-convert nanosecond values to micros before wrapping.","Use LongTimestamp types for sub-microsecond precision needs."],"tags":["timestamp","precision","unsupported-operation"],"backgroundTag":"unsupported-timestamp-precision","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"}