Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COALESCE function #42

Closed
rausnitz opened this issue Oct 17, 2018 · 0 comments
Closed

COALESCE function #42

rausnitz opened this issue Oct 17, 2018 · 0 comments
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@rausnitz
Copy link
Contributor

It would be great if this package could handle queries like:

SELECT COALESCE(SUM(likes), 0) FROM posts WHERE likes > 500;

A recent change to Fluent allows a default value when a SUM() query would result in null: vapor/fluent#573. However, the change requires every SUM() query to be preceded by a separate COUNT() query. A more efficient and reliable solution would be to use COALESCE().

In the example of Fluent's sum() function, you could still pass a nil value for the default, and then the COALESCE() function would result in null if the SUM() is also null.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants