I was testing out the db2 max function to see if it picks NULL as the maximum of a list of nulls.
So I ran this query:
SELECT max (a.colname)
FROM (SELECT null AS colname FROM <replace with any small table name>) a
This, however, gave this error message:
DB2 Database Error: ERROR [428F5] [IBM][DB2/AIX64] SQL0245N The invocation of routine "MAX" is ambiguous. The argument in position "1" does not have a best fit. SQLSTATE=428F5
I was able to test what I was set to do by replacing null with nullif(1,1) and it, indeed, returns null as the maximum value in a list of null values.
According to this page, the sql state means that the function max has different, say implementations or overloads, that could handle the argument a.colname, and hence the error.
I am not sure where I can find more about the implementation of the max function in db2, as the IBM page does not say anything about that.
Any idea on how null and nullif differ in their type, espicially in the context of the max function?
You need to select a datatype for that column, try this:
In your first query, the
MAXdoesn’t know the datatype for that column. In your second query, its assigning a datatype based on the input (in this case, a 1), so it may be saying that is anINT, so it can compute theMAX.