Skip to content

Simplify CASE WHEN false THEN ... #17590

@alamb

Description

@alamb

Is your feature request related to a problem or challenge?

One form of Case statements look like

CASE 
  WHEN <expr> THEN <expr>
  WHEN <expr> THEN <expr>
  ...
   ELSE
END

As suggested by @geoffreyclaude in #17448 (comment)

Any WHEN false will never execute and thus can be removed from the

For example

CASE 
  WHEN false THEN 1  -- never executed
  ELSE 2  
END

Could be simplified to

2

Likewise

CASE 
  WHEN x=y THEN 1 
  WHEN false THEN 2  -- never executed
  ELSE 3  
END

Could be simplified to

CASE 
  WHEN x=y THEN 1 
  ELSE 3  
END

Describe the solution you'd like

I would like to implement the simplification above

Describe alternatives you've considered

I think we can just extend the existing rules for CASE simplification here:

An example is In #17450 where @EeshanBembi implemented a new CASE simplification

Additional context

_No response_¯

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions