Home > OS >  Code workbook, SQL - why is this code not running and producing an error of 'invalid number of
Code workbook, SQL - why is this code not running and producing an error of 'invalid number of

Time:07-06

I'm reporting a potential bug with the ISNULL statement for SQL in code workbook, or if not wondering why my code does not run (image of the select statement of code)? The code runs fine when the column is not wrapped in the ISNULL statement, and the error log quotes that it expects just one argument for ISNULL (though my understanding is that there are two arguments Select statement from the code that I'm attempting to run

Message from the error log Message from the error log

CodePudding user response:

If you are looking for the same functionality in Spark SQL you can try

select if(isnull(OUT2021.financial_year),'',OUT2021.financial_year) as financial_Year from table

OR

spark.sql("""
  select
    case when OUT2021.financial_year is null then '' else OUT2021.financial_year end as financial_Year
  from
    TableName 
""")

CodePudding user response:

There is no bug, Spark sql isnull only takes one argument https://spark.apache.org/docs/2.3.0/api/sql/index.html#isnull

> SELECT isnull(1);
 false

The link you listed is from Microsoft's SQL (Transact-SQL) which is a different syntax.

  • Related