-
Notifications
You must be signed in to change notification settings - Fork 1k
Description
Is your feature request related to a problem? Please describe.
I am implementing ibis-project/ibis#11311, which is trying to compile a FirstValue expression with a include_nulls: bool property.
This is the current behavior of sqlglot:
import sqlglot as sg
duckdb_sql = """SELECT FIRST_VALUE(t1.c1) IGNORE NULLS OVER (PARTITION BY t1.c2 ORDER BY t1.c3) FROM t1;"""
pg_sql = sg.transpile(duckdb_sql, read="duckdb", write="postgres")[0]
print(pg_sql) # SELECT FIRST_VALUE(t1.c1) IGNORE NULLS OVER (PARTITION BY t1.c2 ORDER BY t1.c3) FROM t1
# eg the sql is emitted unchangedBut, if you look at the postgres docs, at the bottom you will find
Note
The SQL standard defines a RESPECT NULLS or IGNORE NULLS option for lead, lag, first_value, last_value, and nth_value. This is not implemented in PostgreSQL: the behavior is always the same as the standard's default, namely RESPECT NULLS. Likewise, the standard's FROM FIRST or FROM LAST option for nth_value is not implemented: only the default FROM FIRST behavior is supported. (You can achieve the result of FROM LAST by reversing the ORDER BY ordering.)
So, the generated SQL above errors at runtime if you actually try to execute it.
Describe the solution you'd like
My question is: Should sqlglot error during compilation? I'm not sure the precedent in other parts of sqlglot.
Describe alternatives you've considered
- throw a warning?
- keep the existing behavior of doing nothing
Additional context
NA