0
votes

I am using sqlalchemy to generate queries and am unsure how to insert the keyword "IGNORE NULLS" between the last_value() window function and the over() function. The sqlalchemy code I have now looks like this:

func.last_value(employee.created).over(partition_by=employee.id)

this generates the following sql in the select statement

LAST_VALUE(employee.created) OVER (PARTITION BY employee.id)

Ideally we would like to insert the keyword "IGNORE NULLS" between the last_value and over function, like this:

LAST_VALUE(employee.created) IGNORE NULLS OVER (PARTITION BY employee.id)

However, I am unsure how to do this using the sqlalchemy library. I am compiling sql for the oracle dialect.

1

1 Answers

0
votes

I wanted to post a hacky solution in case anyone else is having trouble with this:

from sqlalchemy import func, text

func.last_value(employee.created.op('IGNORE')(text('NULLS'))).over(partition_by=employee.id)