Home > Back-end >  Invalid function type [DIV0] for window function in Snowflake
Invalid function type [DIV0] for window function in Snowflake

Time:12-21

I have a table in snowflake, which is getting loaded from multiple tables through transformations. The table is loading fine in postgres.

But when I am running in snowflake it is giving me the error: DIVISION BY ZERO, through analysis, I found out that div by 0 is the cause of it.

So I used div0 function over there as:

 div0(col_1 , sum(col_1)) over(partition by year) as final_col

but that is throwing an error as below:

         Invalid function type [DIV0] for window function

Any idea how to solve this?

CodePudding user response:

DIV0 is not a windowed function. It should be applied on top of windowed function. Position of parantehsis matters:

SELECT div0(col_1 , sum(col_1)) over(partition by year) as final_col
=>
SELECT div0(col_1 , (sum(col_1) over(partition by year)) as final_col
  • Related