Skip to content

[NFR] PHQL: CASE expressions #651

Closed
Closed
@igorgolovanov

Description

@igorgolovanov

I think, we needs to provide a new built-in functionality into PHQL for working with CASE syntax.
There're two syntaxes: Simple CASE and Searched CASE.


Simple CASE syntax

The simple CASE function compares an expression to a set of simple expressions to determine the result.

CASE search-expression
    WHEN expression [, expression [ ... ]] THEN
        statements
    [ WHEN expression [, expression [ ... ]] THEN
        statements
    ... ]
    [ ELSE
        statements ]
END

The simple form of CASE provides conditional execution based on equality of operands.
The search-expression is evaluated (once) and successively compared to each expression in the WHEN clauses.
If a match is found, then the corresponding statements are executed, and then control passes to the next statement after END CASE.
If no match is found, the ELSE statements are executed; but if ELSE is not present, then must be returned a NULL value.


Searched CASE syntax

The searched CASE function evaluates a set of Boolean expressions to determine the result.

CASE
    WHEN boolean-expression THEN
        statements
    [ WHEN boolean-expression THEN
        statements
    ... ]
    [ ELSE
        statements ]
END

The searched form of CASE provides conditional execution based on truth of boolean expressions.
Each WHEN clause's boolean-expression is evaluated in turn, until one is found that yields true.
Then the corresponding statements are executed, and then control passes to the next statement after END CASE.
If no true result is found, the ELSE statements are executed; but if ELSE is not present, then must be returned a NULL value.


General Agreement

  • if ELSE is not present, then must be returned a NULL value. Because different db have a different behavior in this case, i think that PHQL must always add "ELSE NULL" if else not presented in user query.
  • CASE must be closed with END.

Reference Manuals:


Where it implemented?

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions