# Given rows declaration

A `given` stage preceding a query indicates the pipeline expects input "rows" to be provided along when the query is executed. It declares a number of input variables, and the expected type of each variable. If the value provided for a given variable does not match the declared type, an execution error is returned.

For examples on how to pass the given rows for a query, check the driver documentation ( [GRPC](../../../reference/typedb-grpc-drivers/index.md) / [HTTP API](../../../reference/typedb-http-api/index.md) )

## [](#_syntax)Syntax

```typeql
given <var>: <type> [, <var>: <type>, ... ];
```

## [](#_example)Example

Schema for the following examples

```typeql
#!test[schema, commit]
define
  entity content owns id;
  entity page sub content,
    owns page-id,
    owns name;
  entity profile sub page,
    owns username;
  entity user sub profile,
    owns phone,
    owns karma;

  attribute id value string;
  attribute page-id sub id;
  attribute username sub page-id;
  attribute name value string;
  attribute phone value string;
  attribute karma value double;
attribute start-date, value date;
relation friendship relates friend @card(0..2), owns start-date;
user plays friendship:friend;
```

Given rows can be values…​

```typeql
#!test[write, given=name]
given $name: string;
insert $u isa user, has username == $name;
```

or concepts (returned by previous queries).

```typeql
#!test[write, given=u1;u2]
given $u1: user, $u2: user;
insert $_ isa friendship, links (friend: $u1, friend: $u2);
```

Given variables can be optional, allowing for conditional inserts:

```typeql
#!test[write, given=uname;name;phone]
given $uname: username, $name: string, $phone: string?;
match $u isa user, has $uname;
insert
    $u has name == $name;
    try { $u has phone == $phone; };
```

[Edit on GitHub](https://github.com/typedb/typedb-docs/edit/3.x-development/typeql-reference/modules/ROOT/pages/pipelines/given.adoc) Edit this page on GitHub.