Menu

#1724 Unexpected token when comparing function with value

current-release
open
None
5
2024-11-13
2024-11-13
Lukas Eder
No

This simple query doesn't work:

SELECT lower(a) = lower(b)
FROM (VALUES ('A', 'a')) t (a, b)

The error is:

SQL Error [42581]: unexpected token: =

A workaround is to wrap the left expression in parentheses:

SELECT (lower(a)) = lower(b)
FROM (VALUES ('A', 'a')) t (a, b)

The problem doesn't seem to appear in contexts that explicitly expect predicates, e.g. this works:

SELECT 1
FROM (VALUES ('A', 'a')) t (a, b)
WHERE lower(a) = lower(b);

But these also don't work:

SELECT 1
FROM (VALUES ('A', 'a')) t (a, b)
GROUP BY lower(a) = lower(b);

SELECT 1
FROM (VALUES ('A', 'a')) t (a, b)
WHERE COALESCE(lower(a) = lower(b), TRUE);

Discussion

  • Fred Toussi

    Fred Toussi - 2024-11-13
    • assigned_to: Fred Toussi
     
  • Fred Toussi

    Fred Toussi - 2024-11-13

    Thanks Lukas. Will fix next year.

     

Log in to post a comment.

MongoDB Logo MongoDB