Quoting functions seems to be the safest thing to do, so that the function name 
can contain meta-characters and so that the case of the function name matches 
the actual name of the function. Most databases can handle quoted functions, 
even if they are built-ins. 

Apparently PostgreSQL cannot. Is this for all functions, or just for built-ins?

If this is a problem, log a bug against the jdbc-adapter. 

Julian

> On Aug 3, 2017, at 6:08 AM, Muhammad Gelbana <[email protected]> wrote:
> 
> While working on a Drill plugin, Calcite unparsed a JdbcRel node and
> produced the following PostgreSQL query
> 
> SELECT "TEMP( Test)( 535799381)( 0)"
> FROM (SELECT *"STRPOS"*("str1", 'BI') = 1 AS "TEMP( Test)( 535799381)( 0)"
> FROM "TestV1"."Calcs") AS "t"
> GROUP BY "TEMP( Test)( 535799381)( 0)"
> 
> The query fails due to a parsing exception, the reason is that the *STRPOS*
> function name is quoted using double quotes as shown in bold. I tried the
> method manually without quoting the function name and it executed
> successfully.
> 
> I debugged through Calcite and found that the this method
> <https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/SqlUtil.java#L262>
> unparses
> the function name as a plain identifier which leads to the quoting of the
> function name
> <https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/sql/SqlIdentifier.java?deDup474625=1#L287>
> if the dialect supports it.
> 
> Drill uses Calcite v1.4 but as I compared it with the master branch, I
> found them identical.
> 
> So is this a bug ? Has it possible been affecting Calcite through all these
> releases or did I miss anything ?
> 
> Thanks,
> Gelbana

Reply via email to