[FEATURE]: Date and datetime functions for DQL #8687
Labels
area/querylang
Issues related to the query language specification and implementation.
community
Issue or PR created by the community.
kind/feature
Something completely new we should consider.
Use case
It would be extremely useful to cast datetime types to other formats, such as year, month, or day. This way, we could generate meaningful aggregations on datetime types. Example scenario: a simple forum where users can make posts and comments. Each post and comment has a "created date" which is a datetime timestamp. We could then count all posts made in a month (or on a particular day)
Links to Discuss, RFC or previous Issues and PRs
https://discuss.dgraph.io/t/how-to-groupby-date/3040
https://discuss.dgraph.io/t/datetime-functions-are-needed/9694
https://discuss.dgraph.io/t/what-is-dgraph-lacking/16010/79?u=mrwunderbar666
Links to examples and research
For example see postgresql where you can cast a timestamp to year:
Current state
According to my knowledge the current workaround is to create separate fields for year, month, day (in the client application for DGraph) and then run aggregations on these self generated fields. Another solution is the
math()
function withsince()
: https://dgraph.io/docs/query-language/math-on-value-variables/Solution proposal
Example query to aggregate on year:
Other variant:
Additional Information
No response
The text was updated successfully, but these errors were encountered: