Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dateLiteral does not work on OracleDB 12c or 19c #1338

Closed
dakriy opened this issue Sep 8, 2021 · 0 comments · Fixed by #2057
Closed

dateLiteral does not work on OracleDB 12c or 19c #1338

dakriy opened this issue Sep 8, 2021 · 0 comments · Fixed by #2057

Comments

@dakriy
Copy link
Contributor

dakriy commented Sep 8, 2021

The dateLiteral function does not work on OracleDB (and I suspect the other date/datetime literal functions also do not work for the same reason). The following error is generated:

org.jetbrains.exposed.exceptions.ExposedSQLException: java.sql.SQLDataException: ORA-01861: literal does not match format string

here is the relevant subset of the query that was executed

TABLE.DATE_COL = (SELECT MAX (TABLE.DATE_COL)
    FROM TABLE TABLE_ALIAS
    WHERE (TABLE_ALIAS.DATE_COL <= '2021-09-08')
    AND (TABLE_ALIAS.PK = TABLE.PK))

The generated sql for oracle should be something along the lines of:

TABLE.DATE_COL = (SELECT MAX (TABLE.DATE_COL)
    FROM TABLE TABLE_ALIAS
    WHERE (TABLE_ALIAS.DATE_COL <= TO_DATE('2021-09-08', 'YYYY-MM-DD'))
    AND (TABLE_ALIAS.PK = TABLE.PK))

Current workarounds are a custom dateliteral function like this:

fun getSQLDateExpression(date: LocalDate): Expression<*> {
    return if (currentDialect is OracleDialect) {
        CustomDateFunction("TO_DATE", dateLiteral(date), stringLiteral("YYYY-MM-DD"))
    } else {
        dateLiteral(date)
    }
}

OR not using a date literal and using a bind variable.

Tested on oracle 12c and 19c.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant