{"record":{"id":"d94e32cfcde29dd3","repo":"prestodb/presto","slug":"invalid-function-argument-d94e32","errorCode":"INVALID_FUNCTION_ARGUMENT","errorMessage":"Cannot add hour, minutes or seconds to a date","messagePattern":"Cannot add hour, minutes or seconds to a date","errorType":"error_code","errorClass":"PrestoException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/type/DateTimeOperators.java","lineNumber":48,"sourceCode":"import static com.facebook.presto.spi.StandardErrorCode.INVALID_FUNCTION_ARGUMENT;\nimport static com.facebook.presto.util.DateTimeZoneIndex.getChronology;\nimport static com.facebook.presto.util.DateTimeZoneIndex.unpackChronology;\n\npublic final class DateTimeOperators\n{\n    private static final DateTimeField MILLIS_OF_DAY = ISOChronology.getInstanceUTC().millisOfDay();\n    private static final DateTimeField MONTH_OF_YEAR_UTC = ISOChronology.getInstanceUTC().monthOfYear();\n\n    private DateTimeOperators()\n    {\n    }\n\n    @ScalarOperator(ADD)\n    @SqlType(StandardTypes.DATE)\n    public static long datePlusIntervalDayToSecond(@SqlType(StandardTypes.DATE) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right)\n    {\n        if (MILLIS_OF_DAY.get(right) != 0) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Cannot add hour, minutes or seconds to a date\");\n        }\n        return left + TimeUnit.MILLISECONDS.toDays(right);\n    }\n\n    @ScalarOperator(ADD)\n    @SqlType(StandardTypes.DATE)\n    public static long intervalDayToSecondPlusDate(@SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long left, @SqlType(StandardTypes.DATE) long right)\n    {\n        if (MILLIS_OF_DAY.get(left) != 0) {\n            throw new PrestoException(INVALID_FUNCTION_ARGUMENT, \"Cannot add hour, minutes or seconds to a date\");\n        }\n        return TimeUnit.MILLISECONDS.toDays(left) + right;\n    }\n\n    @ScalarOperator(ADD)\n    @SqlType(StandardTypes.TIME)\n    public static long timePlusIntervalDayToSecond(SqlFunctionProperties properties, @SqlType(StandardTypes.TIME) long left, @SqlType(StandardTypes.INTERVAL_DAY_TO_SECOND) long right)\n    {","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/type/DateTimeOperators.java#L30-L66","documentation":"datePlusIntervalDayToSecond rejects adding an INTERVAL DAY TO SECOND to a DATE when the interval has a nonzero time-of-day component (hours/minutes/seconds), since a DATE has no time part. Presto raises INVALID_FUNCTION_ARGUMENT for the operation.","triggerScenarios":"Evaluating date + INTERVAL '5 06:00:00' DAY TO SECOND, or any interval whose MILLIS_OF_DAY component is nonzero.","commonSituations":"Queries ported from systems that truncate time parts, or application code building intervals from durations that include sub-day components.","solutions":["Use an interval with whole days only: date + INTERVAL '5' DAY.","Truncate the interval's time component before adding, or convert the date to TIMESTAMP first if sub-day precision is needed.","If time-of-day math is required, cast the DATE to TIMESTAMP and add the full interval there."],"exampleFix":"// before\nSELECT d + INTERVAL '2 06:30:00' DAY TO SECOND FROM t;\n// after\nSELECT CAST(d AS TIMESTAMP) + INTERVAL '2 06:30:00' DAY TO SECOND FROM t;","handlingStrategy":"validation","validationCode":"-- reject intervals with a time-of-day component before adding to a DATE\nSELECT * FROM t\nWHERE date_add('millisecond', MILLIS_TO_SECONDS_PART(iv), DATE '1970-01-01') IS NOT NULL\n  -- simpler: ensure the literal only uses DAY fields:\n  AND NOT regexp_like(cast(iv AS VARCHAR), '\\d+ \\d{2}:');","typeGuard":"boolean isWholeDays(org.joda.time.ReadableDuration d) { return d.getMillis() % 86400000L == 0; }","tryCatchPattern":"try { result = date + iv; } catch (PrestoException e) { /* INVALID_FUNCTION_ARGUMENT: fall back to TIMESTAMP addition */ }","preventionTips":["Use INTERVAL 'n' DAY literals when the target column is DATE.","Cast DATE to TIMESTAMP whenever sub-day intervals are involved.","Truncate durations to whole days before date arithmetic."],"tags":["presto","datetime","interval","date-arithmetic"],"backgroundTag":"invalid-function-arguments","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"}