{"record":{"id":"9d2d9b002d48c4e3","repo":"prestodb/presto","slug":"timestamp-precision-must-be-in-range-0-d-d","errorCode":null,"errorMessage":"TIMESTAMP precision must be in range [0, %d]: %d","messagePattern":"TIMESTAMP precision must be in range \\[0, (.+?)\\]: (.+?)","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java","lineNumber":81,"sourceCode":"            INSTANCES[p] = new TimestampType(p);\n        }\n    }\n\n    public static final TimestampType TIMESTAMP = INSTANCES[DEFAULT_PRECISION];\n\n    // Keeps the legacy \"timestamp microseconds\" type signature so existing code that matches\n    // on type-signature base strings continues to work without changes.\n    public static final TimestampType TIMESTAMP_MICROSECONDS = INSTANCES[MAX_SHORT_PRECISION];\n\n    private final int precision;\n\n    // Returns the interned instance for p=0..MAX_PRECISION. Only p=3 and p=6 are registered in\n    // the type manager; all other precisions are arithmetic-only until a follow-up change wires\n    // full type-system support (see github.com/prestodb/presto/issues/27934).\n    public static TimestampType createTimestampType(int precision)\n    {\n        if (precision < 0 || precision > MAX_PRECISION) {\n            throw new IllegalArgumentException(format(\n                    \"TIMESTAMP precision must be in range [0, %d]: %d\", MAX_PRECISION, precision));\n        }\n        return INSTANCES[precision];\n    }\n\n    private TimestampType(int precision)\n    {\n        super(buildTypeSignature(precision));\n        this.precision = precision;\n    }\n\n    private static TypeSignature buildTypeSignature(int precision)\n    {\n        if (precision == DEFAULT_PRECISION) {\n            // Preserve \"timestamp\" (no parameter) so existing serialized metadata continues to parse.\n            return parseTypeSignature(StandardTypes.TIMESTAMP);\n        }\n        if (precision == MAX_SHORT_PRECISION) {","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-common/src/main/java/com/facebook/presto/common/type/TimestampType.java#L63-L99","documentation":"TimestampType.createTimestampType only accepts a precision between 0 and MAX_PRECISION (12). Precision values outside that range cannot be represented as a Presto TIMESTAMP type, so the factory interns the instance only after validating the range and throws IllegalArgumentException otherwise.","triggerScenarios":"Calling TimestampType.createTimestampType(p) with p < 0 or p > MAX_PRECISION (e.g. -1, 13, or a precision derived from a parser that mis-reads TIMESTAMP(30)).","commonSituations":"Plugin/connector code constructing timestamp types from metadata strings, ORMs or codegen emitting oversized precisions, or arithmetic on precisions (e.g. p + n for derived types) drifting out of range.","solutions":["Clamp or validate the precision argument to [0, MAX_PRECISION] before calling createTimestampType.","If the precision came from parsing a type string, verify the parsed value (a malformed signature may yield a wrong number).","Use TimestampType.TIMESTAMP / TIMESTAMP_WITH_TIME_ZONE constants for the common p=3 and p=6 cases instead of constructing manually."],"exampleFix":"// before\nTimestampType t = TimestampType.createTimestampType(precision);\n// after\nif (precision < 0 || precision > TimestampType.MAX_PRECISION) {\n    precision = Math.min(Math.max(precision, 0), TimestampType.MAX_PRECISION);\n}\nTimestampType t = TimestampType.createTimestampType(precision);","handlingStrategy":"validation","validationCode":"if (precision < 0 || precision > TimestampType.MAX_PRECISION) {\n    throw new IllegalArgumentException(\"precision out of range [0, \" + TimestampType.MAX_PRECISION + \"]: \" + precision);\n}","typeGuard":"boolean isValidTimestampPrecision(int p) { return p >= 0 && p <= TimestampType.MAX_PRECISION; }","tryCatchPattern":"try {\n    type = TimestampType.createTimestampType(p);\n} catch (IllegalArgumentException e) {\n    type = TimestampType.TIMESTAMP; // safe default\n}","preventionTips":["Clamp precision at config/metadata boundaries before constructing types.","Prefer TimestampType.TIMESTAMP / TIMESTAMP_WITH_TIME_ZONE constants over manual construction.","Unit-test precision parsing with boundary values 0 and MAX_PRECISION."],"tags":["presto","type-system","illegal-argument","timestamp-precision"],"backgroundTag":"invalid-argument-range","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"}