<commit_before>---
title: Insert Queries
keywords: graql, query, insert
tags: [graql]
summary: "Graql Insert Queries"
sidebar: documentation_sidebar
permalink: /docs/querying-data/insert-queries
folder: docs
KB: genealogy-plus
---

The page documents use of the Graql `insert` query, which will insert a specified [variable pattern](./match-clause#variable-patterns)
describing data. To follow along, or experiment further, with the examples given below, please
load the _basic-genealogy.gql_ file, which can be found in the _examples_ directory of the Grakn installation zip, or on
[Github](https://github.com/graknlabs/grakn/blob/master/grakn-dist/src/examples/basic-genealogy.gql).

{% include note.html content="If you are working in the Graql shell, don't forget to `commit` to store an insertion in
the knowledge graph." %}

## `match-insert`

If a [match](./match-clause) is provided, the query will insert the given variable patterns for every result of the query.
The pattern describes [properties](#properties) to set on a particular concept and can optionally be bound to a variable or an ID.

In the example below, we insert additional (fictional) information for a `person` entity who we have matched through `identifier` <NAME>.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell1" data-toggle="tab">Graql</a></li>
    <li><a href="#java1" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell1">
<pre class="language-graql"> <code>
match $p has identifier "<NAME>"; insert $p has middlename "Mathilda"; $p has birth-date 1902-01-01; $p has death-date 1952-01-01; $p has age 50;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java1">
<pre class="language-java"> <code>
qb.match(var("p").has("identifier", "<NAME>"))
    .insert(var("p").has("middlename", "Mathilda"),
        var("p").has("birth-date", LocalDateTime.of(1902, 1, 1, 0, 0, 0)),
        var("p").has("death-date", LocalDateTime.of(1952, 1, 1, 0, 0, 0)),
        var("p").has("age", 50)
    ).execute();
</code>
</pre>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->

## Properties

### isa

Set the type of the inserted concept.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell2" data-toggle="tab">Graql</a></li>
    <li><a href="#java2" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell2">
<pre class="language-graql"> <code>
insert has identifier "Titus Groan" isa person;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java2">
<pre class="language-java"> <code>
qb.insert(var().has("identifier", "Titus Groan").isa("person")).execute();
</code>
</pre>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->

### id

It is not possible to insert a concept with the given id, as this is the job of the system. However, if you attempt to insert by id, you will retrieve a concept if one with that id already exists. The created or retrieved concept can then be modified with further properties.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell3" data-toggle="tab">Graql</a></li>
    <li><a href="#java3" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell3">
<pre class="language-graql"> <code>
<!--test-ignore-->
insert id "1376496" isa person;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java3">
<pre class="language-java"> <code>
<!--test-ignore-->
qb.insert(var().id(ConceptId.of("1376496")).isa("person")).execute();
</code>
</pre>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->

### val

Set the value of the concept.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell4" data-toggle="tab">Graql</a></li>
    <li><a href="#java4" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell4">
<pre class="language-graql"> <code>
insert == "Ash" isa surname;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java4">
<pre class="language-java"> <code>
qb.insert(var().val("Ash").isa("surname")).execute();
</code>
</pre>
</div> <!-- tab-pane --><commit_msg>provide the correct insert query to set val in docs/04/insert-queries<commit_after>---
title: Insert Queries
keywords: graql, query, insert
tags: [graql]
summary: "Graql Insert Queries"
sidebar: documentation_sidebar
permalink: /docs/querying-data/insert-queries
folder: docs
KB: genealogy-plus
---

The page documents use of the Graql `insert` query, which will insert a specified [variable pattern](./match-clause#variable-patterns)
describing data. To follow along, or experiment further, with the examples given below, please
load the _basic-genealogy.gql_ file, which can be found in the _examples_ directory of the Grakn installation zip, or on
[Github](https://github.com/graknlabs/grakn/blob/master/grakn-dist/src/examples/basic-genealogy.gql).

{% include note.html content="If you are working in the Graql shell, don't forget to `commit` to store an insertion in
the knowledge graph." %}

## `match-insert`

If a [match](./match-clause) is provided, the query will insert the given variable patterns for every result of the query.
The pattern describes [properties](#properties) to set on a particular concept and can optionally be bound to a variable or an ID.

In the example below, we insert additional (fictional) information for a `person` entity who we have matched through `identifier` <NAME>.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell1" data-toggle="tab">Graql</a></li>
    <li><a href="#java1" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell1">
<pre class="language-graql"> <code>
match $p has identifier "<NAME>"; insert $p has middlename "Mathilda"; $p has birth-date 1902-01-01; $p has death-date 1952-01-01; $p has age 50;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java1">
<pre class="language-java"> <code>
qb.match(var("p").has("identifier", "<NAME>"))
    .insert(var("p").has("middlename", "Mathilda"),
        var("p").has("birth-date", LocalDateTime.of(1902, 1, 1, 0, 0, 0)),
        var("p").has("death-date", LocalDateTime.of(1952, 1, 1, 0, 0, 0)),
        var("p").has("age", 50)
    ).execute();
</code>
</pre>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->

## Properties

### isa

Set the type of the inserted concept.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell2" data-toggle="tab">Graql</a></li>
    <li><a href="#java2" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell2">
<pre class="language-graql"> <code>
insert has identifier "<NAME>" isa person;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java2">
<pre class="language-java"> <code>
qb.insert(var().has("identifier", "<NAME>").isa("person")).execute();
</code>
</pre>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->

### id

It is not possible to insert a concept with the given id, as this is the job of the system. However, if you attempt to insert by id, you will retrieve a concept if one with that id already exists. The created or retrieved concept can then be modified with further properties.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell3" data-toggle="tab">Graql</a></li>
    <li><a href="#java3" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell3">
<pre class="language-graql"> <code>
<!--test-ignore-->
insert id "1376496" isa person;
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java3">
<pre class="language-java"> <code>
<!--test-ignore-->
qb.insert(var().id(ConceptId.of("1376496")).isa("person")).execute();
</code>
</pre>
</div> <!-- tab-pane -->
</div> <!-- tab-content -->

### val

Set the value of the concept.

<ul id="profileTabs" class="nav nav-tabs">
    <li class="active"><a href="#shell4" data-toggle="tab">Graql</a></li>
    <li><a href="#java4" data-toggle="tab">Java</a></li>
</ul>

<div class="tab-content">
<div role="tabpanel" class="tab-pane active" id="shell4">
<pre class="language-graql"> <code>
insert $x == "Ash" isa surname;
insert $x isa surname "Ash";
</code>
</pre>
</div>
<div role="tabpanel" class="tab-pane" id="java4">
<pre class="language-java"> <code>
qb.insert(var().val("Ash").isa("surname")).execute();
</code>
</pre>
</div> <!-- tab-pane -->
{'fraction_non_alphanumeric': 0.19788554355320617, 'fraction_numerical': 0.015858423350953804, 'mean_word_length': 4.744554455445544, 'pattern_counts': {'":': 0, '<': 219, '<?xml version=': 0, '>': 219, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7243282', 'n_tokens_mistral': 3089, 'n_tokens_neox': 2941, 'n_words': 893}