You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What's going on is the parser reads IF and skips ahead to the next occurrence of THEN, after which it expects the consequent (in this case it should be RAISE EXCEPTION). Instead it stops at the THEN which is part of the CASE expression. This is clearly a faulty assumption and I'll need to actually parse the conditional as an expression.
However, this raises several issues. First, this will need to add state to the parser to track the parentheses nesting level -- something I was fortunately able to avoid until now. Second, it makes sense that we would want to get coverage on each branch within the CASE statement! This is a fairly complicated issue that I would like to address, but perhaps after some careful consideration.
In the meantime, there are several alternate syntaxes that express the same control flow. I realize this may be a simplified example, but consider the following suggestions.
IF ((x = 'abc') is not true) THEN ...
IF (x IS NOT NULL AND x <> 'abc') THEN ...
Probably more acceptable would be to assign the result of the entire CASE expression to a temporary variable. This preserves the CASE statement entirely, allows for code coverage on each WHEN branch, and most importantly will be accepted by the parser.
condition := CASE WHEN x IS NULL THEN false
WHEN x = 'abc' THEN false
ELSE true
END;
IF (condition)
THEN
RAISE EXCEPTION 'error message';
END IF;
IF (CASE
WHEN x IS NULL THEN FALSE
WHEN x = 'abc' THEN FALSE
ELSE TRUE
END)
THEN
RAISE EXCEPTION 'error message';
END IF;
The parser seem to have issues with FALSE. It appears that the parser is assuming there needs to be a assignment that occurs after the FALSE.
The text was updated successfully, but these errors were encountered: