I have figured out a work-around, and I'll share that with those of you searching for a solution.
First of all, it's obvious to me that Teradata's handling of NaN floating point values is incomplete and any behavior I've stumbled into figuring out is likely unintentional and inconsistent across different versions. So I offer the following free advice, with no guarantees, promises, or liabilities of any kind. Caveat emptor.
I'll start with the following desire:
SELECT
SUM(1) AS CNT_VAL,
SUM(VAL) AS SUM_VAL,
SUM(VAL**2) AS SUM_VAL_SQR
FROM
DTMSince my DTM table has values which are NaN, I get error [2622], "Bad argument for ** operator." After drilling down into the data, I find that if I CAST the FLOAT value to a VARCHAR(50), the NaN values come out as a string of 22 asterisks ("**********************"). I can cast to a VARCHAR(1) instead, and the NaN comes out as a single asterisk "*". That comparison isn't all that bad.
WHERE
NOT CAST (VAL AS VARCHAR(1)) = '*'Adding the WHERE clause above does the trick for screening out the NaNs. But I also have some large bogus values I would like to screen out as well, so I alter the WHERE clause some more:
WHERE
NOT CAST (VAL AS VARCHAR(1)) = '*' AND
NOT ABS(VAL) > 1.0e+21Here, I have a problem again. I get error [2651], "Operation Error computing expression involving _____." After much investigation, I found the problem here is in the equality portion of the floating point comparison. What "equality portion," you ask? What seems to be happening here is that the "NOT >" is transformed to "<=" under the covers. I get the same [2651] error if I use "ABS(VAL) <= 1.0e+21". "NOT ABS(VAL) >= 1.0e+21" succeeds, but I decided this is more straight-forward:
WHERE
NOT CAST (VAL AS VARCHAR(1)) = '*' AND
ABS(VAL) < 1.0e+21Equality with the exact floating point value of 1.0e+21 is irrelevant, so functionally this works and accomplishes what I'm trying to do.
The "ABS(VAL) < 1.0e+21" also screens out the NaN values, and thus it seems like I could remove the CAST and comparison to '*'. But this seems to work only intermittently. I cannot reproduce this now, but I have in my history examples of "ABS(VAL) <= 1.0e+21" both working and not working for screening out NaN. Now, I can't get "<=" to work at all. So, I'm leaving the CAST in place, knowing there's a performance hit, but I'm only doing this for a short time as we have stopped the loading of NaN into the table from this point forward.
For the search engines, while investigating this I also ran into errors [2650], "Numeric processor operand error."; [2621], "Bad character in format or data of _____."; and [2623], "Bad argument involving _____ for ** operator." all related to the NaN floating point values. Hopefully this helps future searchers.
↧