Skip to content

The result type computation for COALESCE() is incorrect #4192

@RobertBrunel

Description

@RobertBrunel

The type computation for COALESCE() currently falls back to VariadicFunctionValue#getResultType():

@Override                                                                                                                                                           
public Type getResultType() {
  return children.get(0).getResultType();
}

This returns the type of the first argument. For COALESCE() that is not entirely correct because it will usually get the nullability wrong. The result type of COALESCE() is not-nullable when any argument is non-nullable. A common idiom is COALESCE(…, 0), whose result is not nullable.

Fixing this should unlock some opportunities for simplifying and constant-folding expressions containing COALESCE().

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions