Vars can be assigned only when grouped by UID attribute

hello everyone
I have the same error

Vars can be assigned only when grouped by UID attribute while executing this query

{
 var(func: has(evt_uniq_visitor)) @groupby(evt_uniq_visitor){
     data as  count(uid)
  }
  res(func:uid(data)){
  evt_uniq_visitor  
  }
  
  
}

but I remove res function work very well also I tested the same query in another database it works I don’t know why doesn’t work here and what this error mean

1 Like

Is it like this?

{
  xx(func: has(evt_uniq_visitor)) @groupby(evt_uniq_visitor){
     count(uid)
  }
}

This is correct because you do not use var.

evt_uniq_visitor is an attribute of a vertex, not an edge, so var cannot be used when grouping by it.
This is a limitation of dql, no way.

1 Like

but I execute the same query in another database it works for me
also, I wanna get data for each evt_uniq_visitor that’s why I want to get them in var

just ran into this issue. frustrating.

edit: looks like a fix(?) for this has been merged into master: feat(DQL): @groupby on scalar fields and count duplicate by minhaj-shakeel · Pull Request #7746 · dgraph-io/dgraph · GitHub