# First with Value Variable doesnt work

**URL:** <https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958>\
**Category:** Dgraph\
**Tags:** dgraph, status:accepted, kind:feature, ticket:created\
**Created:** [February 25, 2021, 2:16pm UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958 "2021-02-25T14:16:01Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Florian](https://avatars.discourse-cdn.com/v4/letter/f/898d66/32.png) [@Florian](https://discuss.dgraph.io/u/Florian)\
**Post date:** [February 25, 2021, 2:16pm UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/1 "2021-02-25T14:16:01Z")

</div>

## Report a Dgraph Bug

### What version of Dgraph are you using?

> **Dgraph Version**
>
> ```auto
> $ dgraph version
>  
> v20.11.0
> 
> ```

### Have you tried reproducing the issue with the latest release?

### What is the hardware spec (RAM, OS)?

### Steps to reproduce the issue (command/config used to run Dgraph).

Run an Query with a Value Variable and this constellation!

length as SOMEPREDICATE

and use it in for example first

(first: val(length))

I get this exception!

```auto
{
  "name": "t",
  "url": "http://localhost:8080/query?timeout=20s",
  "errors": [
    {
      "message": ": while converting to subgraph: strconv.ParseInt: parsing \"ct\": invalid syntax",
      "extensions": {
        "code": "ErrorInvalidRequest"
      }
    }
  ]
}

```

I tried several things, defining predicate as string, integer, used count, max, min

Everytime u get this error!

### Expected behaviour and actual result.

It should take the value and use it to limit the elements

Found similar Topic where the last statment is on fixed bug

> **[Support value variables for paging params (offset, after, first)](https://discuss.dgraph.io/t/support-value-variables-for-paging-params-offset-after-first/8753/4)**
>
> romshark commented : I think I faced a similar problem working on my dgraph tech-demo. I’m trying to implement pagination and this is the query I assumed to work: query PostsPage( $first: int = 4, $id: string =...

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [February 26, 2021, 3:22am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/2 "2021-02-26T03:22:23Z")

</div>

Hi,

I didn’t quite understand the steps to reproduce it. Do you mean something like this:

```auto
{
  var (func: allofterms(name@en, "Steven Spielberg")) @filter(has(director.film)){
  	length as count(director.film)
  }
  me(func: allofterms(name@en, "Steven Spielberg")) @filter(has(director.film)){
    director.film(first: val(length)) {
      name@en
    }
  }
}

```

If this is the case, then you’re right - it doesn’t work.

I’m doubtful of the previous claim that this was in the changelist for 20.07. @hardik can you please check this out?

EDIT: I found the Pull Request:

> <https://github.com/dgraph-io/dgraph/pull/6634>
>
> \<!--
> Your title must be in the following format: topic(Area): Feature
> Topic mu…st be one of build|ci|docs|feat|fix|perf|refactor|chore|test
> 
> Sample Titles:
> feat(Enterprise): Backups can now get credentials from IAM
> fix(Query): Skipping floats that cannot be Marshalled in JSON
> perf: \[Breaking\] json encoding is now 35% faster if SIMD is present
> chore: all chores/tests will be excluded from the CHANGELOG
> 
> Please add a description with these things:
> 1. A good description explaining the problem and what you changed.
> 2. If it fixes any GitHub issues, say "Fixes #GitHubIssue".
> 3. If it corresponds to a Jira issue, say "Fixes DGRAPH-###".
> 4. If this is a breaking change, please put "\[Breaking\]" in the title. In the description, please put a note with exactly who these changes are breaking for.
> \--\>
> Pagination param "after" does not work when using func: uid(v)
> 
> for query
> \`\`\`
> {
> var(func: has(name@en), first: 50) {
> test as uid
> }
> 
> ss(func: uid(test), first: 2, after: 0x6) {
> uid
> }
> }
> \`\`\`
> 
> the response was
> 
> \`\`\`
> {
> "data": {
> "ss": \[
> {
> "uid": "0x4"
> },
> {
> "uid": "0x6"
> }
> \]
> }
> }
> \`\`\`
> 
> 
> \---
> This change is \[\<img src="https://reviewable.io/review\_button.svg" height="34" align="absmiddle" alt="Reviewable"/\>\](https://reviewable.io/reviews/dgraph-io/dgraph/6631)
> 
>  
> 
> Docs Preview: \[\<img src="https://bl.ocks.org/prashant-shahi/raw/3a9f99bec84231cfe3c0e82cf883f159/0e588d908ad8c8b10958b87ebdd2ba68779ccf4f/dgraph.svg" height="34" align="absmiddle" alt="Dgraph Preview"/\>\](https://dgraph-70fd76f0af-98614.surge.sh)

It is specific to `uid()`, not `val()`

So I’m accepting this as a feature request

---

<div class="post-metadata">

**Author:** ![Florian](https://avatars.discourse-cdn.com/v4/letter/f/898d66/32.png) [@Florian](https://discuss.dgraph.io/u/Florian)\
**Post date:** [February 26, 2021, 5:22am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/4 "2021-02-26T05:22:23Z")

</div>

Good morning!

Yes thats exactly what I mean!

I saw the linked post and didn’t know if its already implemented!

But it seems too

Atleast what I understand from error I have got

```auto
while converting to subgraph: strconv.ParseInt: parsing \"ct\": invalid syntax

```

The error didn’t say that it can’t convert **val** (), it can’t convert the value of variable

Am I right in this theorie?

Greetings

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [February 26, 2021, 5:59am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/5 "2021-02-26T05:59:50Z")

</div>

So the steps in handling a query is something along the lines of this (things in bold are data structures, things not in bold are functions):

Query –[parse](https://github.com/dgraph-io/dgraph/blob/master/gql/parser.go#L534) → [**GraphQuery**](https://github.com/dgraph-io/dgraph/blob/master/gql/parser.go#L48) –[convert to SubGraph](https://github.com/dgraph-io/dgraph/blob/master/query/query.go#L746) → [**SubGraph**](https://github.com/dgraph-io/dgraph/blob/master/query/query.go#L252) –[process request](https://github.com/dgraph-io/dgraph/blob/master/query/query.go#L2738) → Results  
… … … **↑↑↑** … … … …  
The error happens in the parse phase (where the arrows point to).

That is, our language spec doesn’t allow for identifiers at that position. The spec needs to be updated to allow that.

---

<div class="post-metadata">

**Author:** ![Florian](https://avatars.discourse-cdn.com/v4/letter/f/898d66/32.png) [@Florian](https://discuss.dgraph.io/u/Florian)\
**Post date:** [February 26, 2021, 6:11am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/6 "2021-02-26T06:11:08Z")

</div>

Ah okay.

Is there any estimation when this get’s implemented?

I would need it for a project

Thanks!

---

<div class="post-metadata">

**Author:** ![chewxy](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/chewxy/32/4339_2.png) [@chewxy](https://discuss.dgraph.io/u/chewxy)\
**Post date:** [February 26, 2021, 6:14am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/7 "2021-02-26T06:14:27Z")

</div>

Unfortunately I won’t be able to give you an estimate. @hardik might, since he’s managing the queue and features.

---

<div class="post-metadata">

**Author:** ![hardik](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/hardik/32/5053_2.png) [@hardik](https://discuss.dgraph.io/u/hardik)\
**Post date:** [March 1, 2021, 9:56am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/9 "2021-03-01T09:56:45Z")

</div>

We are analyzing whether this should be part of Dgraph or not. We will keep you posted.

---

<div class="post-metadata">

**Author:** ![minhaj](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/minhaj/32/3468_2.png) [@minhaj](https://discuss.dgraph.io/u/minhaj)\
**Post date:** [March 3, 2021, 10:46am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/10 "2021-03-03T10:46:07Z")

</div>

Hey @Florian, Currently variables are not supported in `first` and `offset` parameters. However, can you elaborate on your use case with some sample queries so that we can look into it?

---

<div class="post-metadata">

**Author:** ![hardik](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/hardik/32/5053_2.png) [@hardik](https://discuss.dgraph.io/u/hardik)\
**Post date:** [March 19, 2021, 5:50am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/11 "2021-03-19T05:50:56Z")

</div>

@Florian would you help Minhaj with his query?? ^^

---

<div class="post-metadata">

**Author:** ![Florian](https://avatars.discourse-cdn.com/v4/letter/f/898d66/32.png) [@Florian](https://discuss.dgraph.io/u/Florian)\
**Post date:** [March 26, 2021, 5:25am UTC](https://discuss.dgraph.io/t/first-with-value-variable-doesnt-work/12958/12 "2021-03-26T05:25:47Z")

</div>

Hello,  
I am sorry for my late answer, the last weeks I was on hurry!

Example:

```auto
query {
	array(func: uid(0x2723)){
		l as Length
    Array(first: val(l))
    {
			name
    }
  }
}

```

```auto
{
  "set":
	{
    "uid": "_:root",
    "Length": 10,
    "Array":[
        {
            "name": "1"
        },
        {
            "name": "2"
        },
        {
            "name": "3"
        },
        {
            "name": "4"
        },
        {
            "name": "5"
        },
        {
            "name": "6"
        },
        {
            "name": "7"
        }
    ]
	}
}

```

Greetings  
Florian
