# Min, max: Support more than two arguments

**URL:** https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404
**Category:** Dgraph
**Tags:** area:parsing, area:querylang, dgraph, kind:enhancement, status:accepted
**Created:** [June 13, 2017, 6:33am UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404 "2017-06-13T06:33:24Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [June 13, 2017, 6:33am UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/1 "2017-06-13T06:33:24Z")

</div>

**Moved from GitHub [dgraph/1050](https://github.com/dgraph-io/dgraph/issues/1050)**

_Posted by_ [sungwoncho](https://github.com/sungwoncho):

Version: 0.7.7

* * *

When aggregating using `min` or `max`, as a user I would like to do the following:

```
max(v1, v2, v3)

```

rather than

```
max(max(v1, v2), v3)

```

Therefore it might be useful if `min` and `max` supported more than two arguments.

Use case: [https://gist.github.com/sungwoncho/ddba3a287ad87288331c493c2de5a5cb#file-get\_active\_answers](https://gist.github.com/sungwoncho/ddba3a287ad87288331c493c2de5a5cb#file-get_active_answers)

* * *

Dataset:

[dgraph-1-2017-07-10-18-51.rdf.gz](https://github.com/dgraph-io/dgraph/files/1134923/dgraph-1-2017-07-10-18-51.rdf.gz)  
[dgraph-schema-1-2017-07-10-18-51.rdf.gz](https://github.com/dgraph-io/dgraph/files/1134924/dgraph-schema-1-2017-07-10-18-51.rdf.gz)

Query:

```auto
# You might need to change the value of id
{
  var (id: 0xd18499a5ac49c3a6) {
    Has.Answer {
      answerTs as Timestamp
      ~Post {
        historyTs as Timestamp
      }
      Comment {
        commentTs as Timestamp
      }
      commentTsMax as max(var(commentTs))
      historyTsMax as max(var(historyTs))
      lastActive as math(max(max(answerTs, commentTsMax), historyTsMax))
      # The following line should work, if replaced with the above line
      # lastActive as math(max(answerTs, commentTsMax, historyTsMax))
    }
  }

  question(id: 0xd18499a5ac49c3a6) {
    Has.Answer(orderdesc: var(lastActive)) {
      Body {
        Text
      }
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [July 3, 2017, 2:23am UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/2 "2017-07-03T02:23:52Z")

</div>

[ashwin95r](https://github.com/ashwin95r) _commented_ :

Ping, @abhishekgahlot . Are you still on it?

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [July 3, 2017, 6:49pm UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/3 "2017-07-03T18:49:28Z")

</div>

[abhishekgahlot](https://github.com/abhishekgahlot) _commented_ :

@ashwin95r Yes, I am still working on this. Will give update soon.

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [February 2, 2018, 8:08am UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/4 "2018-02-02T08:08:25Z")

</div>

[kshitij10496](https://github.com/kshitij10496) _commented_ :

@pawanrawal Would it be fine if I give this a try?

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [February 2, 2018, 8:09am UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/5 "2018-02-02T08:09:21Z")

</div>

[pawanrawal](https://github.com/pawanrawal) _commented_ :

Sure, go ahead and give it a try @kshitij10496.

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [February 4, 2019, 10:47pm UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/6 "2019-02-04T22:47:15Z")

</div>

[martinmr](https://github.com/martinmr) _commented_ :

Update: I tried working on this and I got some basic math expressions to work with min and max using more than two arguments. However, there are some bugs in the parser that are caused by the need of knowing exactly how many arguments a function needs. Since this is a very basic assumption, I would need to rework the entire parser, which requires a lot more work than I initially thought.

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [February 12, 2019, 4:54am UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/7 "2019-02-12T04:54:33Z")

</div>

[srfrog](https://github.com/srfrog) _commented_ :

@sungwoncho and @martinmr see the attached PR for a possible solution. Thx

---

<div class="post-metadata">

### Author: ![diggy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/diggy/32/3666_2.png) [@diggy](https://discuss.dgraph.io/u/diggy)
#### Post date: [July 23, 2019, 7:16pm UTC](https://discuss.dgraph.io/t/min-max-support-more-than-two-arguments/8404/8 "2019-07-23T19:16:13Z")

</div>

[martinmr](https://github.com/martinmr) _commented_ :

Assigning to @pawanrawal to see if he has better luck with this than Gus and I did.
