sequelize / sequelize/sequelize
Implementing PostgreSQL "SUM(field) FILTER (WHERE condition)"
Open
Nobody has claimed this yet.
dialect: postgres
existing workaround
status: awaiting response
- Dominant language
- TypeScript
- Stars
- 30.4k
- Forks
- 4.3k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 68
Description
I wonder if there is a proper way of writing the SUM FILTER expression besides wrapping the whole SQL as a literal(). The fn() does not seem to support post-clauses, neither literal() allows concatenation of multiple parameters:
db.literal(
db.fn('sum', db.col(field1)),
'FILTER (WHERE',
db.where(db.col(field2), '>', value),
')'
);
Thanks.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names fn(), literal(), db.col(), and db.where(), but no files or tests. Start by tracing how these expression helpers generate PostgreSQL SQL and review the existing discussion for the intended API. Done means SUM(field) FILTER (WHERE condition) can be expressed without wrapping the complete SQL in literal().
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100