Skip to content
This repository has been archived by the owner on Jan 28, 2021. It is now read-only.

IsNullable does not retain null when we return nil in expressions #546

Closed
theodesp opened this issue Nov 13, 2018 · 0 comments · Fixed by #555
Closed

IsNullable does not retain null when we return nil in expressions #546

theodesp opened this issue Nov 13, 2018 · 0 comments · Fixed by #555
Assignees
Labels
bug Something isn't working

Comments

@theodesp
Copy link
Contributor

I'm trying to implement nullif and I assign the return of IsNullable as true:

func (ni *NullIf) IsNullable() bool { return true }

// Type implements the sql.Expression interface.
func (ni *NullIf) Type() sql.Type {
	return ni.Left.Type()
}

Then in the code at some point in the Eval function I return nil to indicate that the 2 values are equal:

        expr:= expression.NewEquals(ni.Left, ni.Right)
	areEqual, err := expr.Eval(ctx, row)
	if err != nil {
		return nil, err
	}

	if areEqual.(bool) {
		return nil, nil
	}
	return left, nil

However when I use numbers then the nil become 0 which is wrong

+--------------+
| nullif(1, 1) |
+--------------+
|            0 |
+--------------+
@ajnavarro ajnavarro added the bug Something isn't working label Nov 13, 2018
@kuba-- kuba-- self-assigned this Nov 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants