timgrein commented on code in PR #3869:
URL: https://github.com/apache/calcite/pull/3869#discussion_r1687093893


##########
testkit/src/main/java/org/apache/calcite/test/SqlOperatorTest.java:
##########
@@ -10857,6 +10857,7 @@ void assertSubFunReturns(boolean binary, String s, int 
start,
     f.checkFails("trim('' from 'abcde')",
         "Trim error: trim character must be exactly 1 character",
         true);
+    f.checkFails("trim()", "String to trim cannot be null", false);

Review Comment:
   The creator of the original 
https://issues.apache.org/jira/browse/CALCITE-6145 suggested to throw an 
exception with an exact description.
   
   I've checked the behavior of PostgreSQL (v15):
   
   ```sql
   SELECT TRIM() AS trimmed_string;
   ```
   
   leads to a syntax error: `Query Error: error: syntax error at or near ")"`.
   
   ```sql
   SELECT TRIM("") AS trimmed_string;
   ```
   
   leads to an error: `Query Error: error: zero-length delimited identifier at 
or near """"`.
   
   ```sql
   SELECT TRIM(null) AS trimmed_string;
   ```
   
   returns `null`.
   
   So I think this aligns with the behavior of PostgreSQL throwing an error 
during query parsing, _but_ I think the message could be a bit better: `trim 
cannot be called without arguments` maybe? 
   
   I've added an explicit test for when the value is `null`, which indeed 
returns `null` (aligns with PostgreSQL's behavior).
   
   WDYT? @mihaibudiu 



-- 
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