xiedeyantu commented on code in PR #4712:
URL: https://github.com/apache/calcite/pull/4712#discussion_r2652099704


##########
babel/src/test/java/org/apache/calcite/test/BabelTest.java:
##########
@@ -490,4 +490,59 @@ private void checkSqlResult(String funLibrary, String 
query, String result) {
         .query(query)
         .returns(result);
   }
+
+  /** Test case for
+   * <a 
href="https://issues.apache.org/jira/browse/CALCITE-7337";>[CALCITE-7337]
+   * Add age function (enabled in PostgreSQL library)</a>. */
+  @Test void testAgeFunction() {
+    checkSqlResult("postgresql",
+        "SELECT AGE(timestamp '2023-12-25', timestamp '2020-01-01') FROM 
(VALUES (1)) t",
+        "EXPR$0=3 years 11 mons 24 days 0 hours 0 mins 0.0 secs\n");
+
+    checkSqlResult("postgresql",
+        "SELECT AGE(timestamp '2023-01-01', timestamp '2023-01-01') FROM 
(VALUES (1)) t",
+        "EXPR$0=0 years 0 mons 0 days 0 hours 0 mins 0.0 secs\n");
+
+    checkSqlResult("postgresql",
+        "SELECT AGE(timestamp '2020-01-01', timestamp '2023-12-25') FROM 
(VALUES (1)) t",
+        "EXPR$0=-3 years -11 mons -24 days 0 hours 0 mins 0.0 secs\n");
+
+    checkSqlResult("postgresql",
+        "SELECT AGE(timestamp '2023-02-01', timestamp '2023-01-31') FROM 
(VALUES (1)) t",
+        "EXPR$0=0 years 0 mons 1 days 0 hours 0 mins 0.0 secs\n");
+
+    checkSqlResult("postgresql",
+        "SELECT AGE(timestamp '2023-12-26 14:30:00', timestamp '2023-12-25 
14:30:00') FROM (VALUES (1)) t",
+        "EXPR$0=0 years 0 mons 1 days 0 hours 0 mins 0.0 secs\n");
+
+    checkSqlResult("postgresql",
+        "SELECT AGE(timestamp '2023-12-25 00:00:00', timestamp '2020-01-01 
23:59:59') FROM (VALUES (1)) t",
+        "EXPR$0=3 years 11 mons 23 days 0 hours 0 mins 1.0 secs\n");
+

Review Comment:
   I want to know what the result of this SQL query is.
   ```
   SELECT AGE(TIMESTAMP '1957-06-13', NULL);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to