/ View Ticket
Ticket Hash: 0c620df60bffd9ef1ca30268a67a9764698c2bcc
Title: LIKELY(), UNLIKELY() and LIKELIHOOD() have affinities
Status: Fixed Type: Code_Defect
Severity: Minor Priority: Immediate
Subsystem: Unknown Resolution: Fixed
Last Modified: 2019-06-11 21:02:25
Version Found In:
User Comments:
mrigger added on 2019-06-11 19:24:14: (text/x-fossil-wiki)
Consider the statements below:

SELECT LIKELY(CAST(1 AS INT)) = '1'; -- expected: 0, actual: 1
SELECT UNLIKELY(CAST(1 AS INT)) = '1'; -- expected: 0, actual: 1
SELECT LIKELIHOOD(CAST(1 AS INT), 0.5) = '1'; -- expected: 0, actual: 1

All statements return 1, which is somehow unexpected, since functions are expected to have no affinity; however, it seems that for these functions, the affinity of the function argument is assumed (for LIKELIHOOD, the affinity of the first argument is taken).

This bug report is similar to [d60b3cd7cb], where it was reported that the COLLATE operator takes the affinity of the expression applied to, and resulted in a documentation update.