calcite icon indicating copy to clipboard operation
calcite copied to clipboard

[CALCITE-5634] Add LEAST, GREATEST for PostgreSQL

Open dssysolyatin opened this issue 2 years ago • 5 comments

dssysolyatin avatar Apr 06 '23 08:04 dssysolyatin

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

sonarqubecloud[bot] avatar Apr 06 '23 10:04 sonarqubecloud[bot]

I think it could be a good idea to add Postgres to the list of libraries these functions are tested for in SqlOperatorTest.

tanclary avatar Apr 06 '23 16:04 tanclary

+1 for what @tanclary said, we should improve the test for these functions to ensure they works well for PostgreSQL

zoudan avatar Apr 07 '23 13:04 zoudan

It turned out that it is not enough to just enable this function. PostgreSQL's LEAST, GREATEST functions behave differently with NULL values than ORACLE or BigQuery:

From BigQuery documentation [1]:

They return NULL if any of the input parameters is NULL.

From PostgreSQL documentation [2]:

The result will be NULL only if all the expressions evaluate to NULL.

[1] https://cloud.google.com/bigquery/docs/reference/standard-sql/mathematical_functions [2] https://www.postgresql.org/docs/15/functions-conditional.html#FUNCTIONS-GREATEST-LEAST

dssysolyatin avatar Apr 08 '23 07:04 dssysolyatin

I was going to suggest changing the commit message to 'Enable GREATEST, LEAST functions in Postgres library' for consistency with other commits.

But it seems that you need two new functions. (Similar to SUBSTR_POSTGRESQL.)

julianhyde avatar Apr 10 '23 17:04 julianhyde