diff --git a/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java b/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java index 04e4bb13cf14..9cccc5e4484c 100644 --- a/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java +++ b/babel/src/test/java/org/apache/calcite/test/BabelParserTest.java @@ -213,15 +213,16 @@ class BabelParserTest extends SqlParserTest { /** PostgreSQL and Redshift allow TIMESTAMP literals that contain only a * date part. */ @Test void testShortTimestampLiteral() { + // Parser doesn't actually check the contents of the string. The validator + // will convert it to '1969-07-20 00:00:00', when it has decided that + // TIMESTAMP maps to the TIMESTAMP type. sql("select timestamp '1969-07-20'") - .ok("SELECT TIMESTAMP '1969-07-20 00:00:00'"); + .ok("SELECT TIMESTAMP '1969-07-20'"); // PostgreSQL allows the following. We should too. sql("select ^timestamp '1969-07-20 1:2'^") - .fails("Illegal TIMESTAMP literal '1969-07-20 1:2': not in format " - + "'yyyy-MM-dd HH:mm:ss'"); // PostgreSQL gives 1969-07-20 01:02:00 + .ok("SELECT TIMESTAMP '1969-07-20 1:2'"); sql("select ^timestamp '1969-07-20:23:'^") - .fails("Illegal TIMESTAMP literal '1969-07-20:23:': not in format " - + "'yyyy-MM-dd HH:mm:ss'"); // PostgreSQL gives 1969-07-20 23:00:00 + .ok("SELECT TIMESTAMP '1969-07-20:23:'"); } /** Tests parsing PostgreSQL-style "::" cast operator. */ diff --git a/core/src/main/codegen/templates/Parser.jj b/core/src/main/codegen/templates/Parser.jj index 0514b815e2f3..4db4d15083f5 100644 --- a/core/src/main/codegen/templates/Parser.jj +++ b/core/src/main/codegen/templates/Parser.jj @@ -4609,15 +4609,24 @@ SqlLiteral DateTimeLiteral() : } | { s = span(); } p = SimpleStringLiteral() { - return SqlParserUtil.parseDateLiteral(p, s.end(this)); + return SqlLiteral.createUnknown("DATE", p, s.end(this)); + } +| + { s = span(); } p = SimpleStringLiteral() { + return SqlLiteral.createUnknown("DATETIME", p, s.end(this)); } |