<commit_before># SQL - CREATE EDGE

This command creates a new Edge into the database. Edges, together with Vertices, are the main components of a Graph. OrientDB supports polymorphism on edges. The base class is "E". Look also how to [Create Vertex](SQL-Create-Vertex.md).

## Control vertices version increment
Creation and deletion of edges cause updating of versions in involved vertices. To avoid this behavior use Bonsai structure. By default Bonsai is used as soon as the threshold is reached to optimize operations. To always use Bonsai, set this configuration on JVM (or in `orientdb-server-config.xml` file): 

```
-Dindex.embeddedToSbtreeBonsaiThreshold=-1
``` 
Or in Java by calling this before opening the database:

```java
OGlobalConfiguration.INDEX_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
```



| ![NOTE](images/warning.png) | _NOTE: While running as distributed, edge creation could be done in two steps (create+update). This could break some constraint defined at Edge's class level. To avoid this kind of problem disable the constrains in Edge's class._ |
|----|----|

## Syntax

```sql
CREATE EDGE <class> [CLUSTER <cluster>] FROM <rid>|(<query>)|[<rid>]* TO <rid>|(<query>)|[<rid>]*
                    [SET <field> = <expression>[,]*]|CONTENT {<JSON>}
                    [RETRY <retry> [WAIT <pauseBetweenRetriesInMs]]
```

Where:
- **class**, is the Edge's class name, or "E" if you don't use sub-types
- **cluster**, is the cluster name where to physically store the edge
- **JSON**, is the JSON content to set as record content, instead of field by field
- **retry**, is the number of retries in case of conflict (optimistic approach)
- **pauseBetweenRetriesInMs**, are the milliseconds of delay between retries

## Examples

### Create a new edge between two vertices of the base class 'E', namely OGraphEdge

```sql
create edge from #10:3 to #11:4
```

### Create a new edge type and a new edge of the new type

```sql
create class E1 extends E
create edge E1 from #10:3 to #11:4
```

### Create a new edge in a particular cluster

```sql
create edge E1 cluster EuropeEdges from #10:3 to #11:4<commit_msg>Updated SQL Create Edge (markdown)<commit_after># SQL - CREATE EDGE

This command creates a new Edge into the database. Edges, together with Vertices, are the main components of a Graph. OrientDB supports polymorphism on edges. The base class is "E". Look also how to [Create Vertex](SQL-Create-Vertex.md).

## Control vertices version increment
Creation and deletion of edges cause updating of versions in involved vertices. To avoid this behavior use Bonsai structure. By default Bonsai is used as soon as the threshold is reached to optimize operations. To always use Bonsai, set this configuration on JVM (or in `orientdb-server-config.xml` file): 

```
-Dindex.embeddedToSbtreeBonsaiThreshold=-1
``` 
Or in Java by calling this before opening the database:

```java
OGlobalConfiguration.INDEX_EMBEDDED_TO_SBTREEBONSAI_THRESHOLD.setValue(-1);
```



| ![NOTE](images/warning.png) | _NOTE: While running as distributed, edge creation could be done in two steps (create+update). This could break some constraint defined at Edge's class level. To avoid this kind of problem disable the constrains in Edge's class._ |
|----|----|

## Syntax

```sql
CREATE EDGE <class> [CLUSTER <cluster>] FROM <rid>|(<query>)|[<rid>]* TO <rid>|(<query>)|[<rid>]*
                    [SET <field> = <expression>[,]*]|CONTENT {<JSON>}
                    [RETRY <retry> [WAIT <pauseBetweenRetriesInMs]]
```

Where:
- **class**, is the Edge's class name, or "E" if you don't use sub-types
- **cluster**, is the cluster name where to physically store the edge
- **JSON**, is the JSON content to set as record content, instead of field by field
- **retry**, is the number of retries in case of conflict (optimistic approach)
- **pauseBetweenRetriesInMs**, are the milliseconds of delay between retries

## Examples

### Create a new edge between two vertices of the base class 'E'

```sql
create edge from #10:3 to #11:4
```

### Create a new edge type and a new edge of the new type

```sql
create class E1 extends E
create edge E1 from #10:3 to #11:4
```

### Create a new edge in a particular cluster

```sql
create edge E1 cluster EuropeEdges from #10:3 to #11:4
{'fraction_non_alphanumeric': 0.10890858208955224, 'fraction_numerical': 0.010727611940298507, 'mean_word_length': 4.24969400244798, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '2178648', 'n_tokens_mistral': 1300, 'n_tokens_neox': 1221, 'n_words': 573}