---
title: "Graph types: GRAPH_OBJECT and PATH"
description: "The CoraDB graph data types: GRAPH_OBJECT, a reference to any vertex or edge, and PATH, the value of a path variable in MATCH."
url: "https://www.coradb.ai/manual/sql/datatype_graph.html"
markdown_url: "https://www.coradb.ai/manual/markdown/sql/datatype_graph.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb graph_object, path type, path variable, graph types, nodes, relationships, match"
---

# Graph types: GRAPH_OBJECT and PATH

CoraDB has two data types for graph queries. Both are used together with [MATCH](https://www.coradb.ai/manual/graph/match.html) and the [graph functions](https://www.coradb.ai/manual/sql/function/graph_fn.html).

| Type | Value | Created by |
|---|---|---|
| **PATH** | An ordered sequence of vertices and the edges between them | A path variable in a **MATCH** clause |
| **GRAPH_OBJECT** | A reference to one vertex or edge, of any vertex or edge table | **CAST** of a vertex or edge |

The examples use the e-commerce sample graph, in which customers *like* products (`likes` edges from `customer` to `product`). A path of two `likes` edges, matched without direction, leads from a product to a customer who liked it and on to another product that customer liked.


## Path type

A **PATH** value is created by a *path variable* in a **MATCH** clause, written `path_variable = pattern`. It contains the vertices and edges matched by the pattern, in order. See [Path variables](https://www.coradb.ai/manual/graph/match.html#path-variables).

- A path exists only within the query that matches it. It cannot be created with a literal, stored in a table column (`PATH is not defined`), or passed between queries.
- Read its parts with [nodes()](https://www.coradb.ai/manual/sql/function/graph_fn.html#nodes) and [relationships()](https://www.coradb.ai/manual/sql/function/graph_fn.html#relationships), which return LISTs, and measure it with [path_size()](https://www.coradb.ai/manual/sql/function/graph_fn.html#path_size). [path_comp()](https://www.coradb.ai/manual/sql/function/graph_fn.html#path_comp) collects values from matching paths without a **FROM MATCH** clause.

```sql
SELECT p2.name AS other_product,
       size(nodes(pth)) AS vertex_count,
       size(relationships(pth)) AS edge_count,
       path_size(pth) AS path_size
FROM MATCH pth = (p1:product)-[l:likes{2,2}]-(p2:product)
WHERE p1.name = 'Vegie-spread' AND p1 <> p2
ORDER BY 1
LIMIT 3;
```

| other_product | vertex_count | edge_count | path_size |
|---|---|---|---|
| Abominable Hoodie | 3 | 2 | 2 |
| Aeon Capri | 3 | 2 | 2 |
| Arcadio Gym Short | 3 | 2 | 2 |

Each path has three vertices (product, customer, product) and two edges.


## Graph object type

A **GRAPH_OBJECT** value refers to a vertex or an edge without fixing its table. It lets you handle the elements of a path, which can come from different vertex and edge tables, in one list.

- A **GRAPH_OBJECT** is obtained with **CAST**: `CAST(v AS GRAPH_OBJECT)` for one element, or `CAST(nodes(pth) AS SEQUENCE(GRAPH_OBJECT))` for the vertices of a path. With [list_comp()](https://www.coradb.ai/manual/sql/function/list_fn.html#list_comp) each element can be cast separately.
- Internally it is an object identifier (OID). Drivers return it as an opaque reference, and corasql prints it as an OID such as `(0|3585|1)`; OIDs differ from database to database.
- Read the properties of the element with [property_of()](https://www.coradb.ai/manual/sql/function/information_fn.html#fn-property-of), giving the table the element belongs to.
- A table column can be declared as **GRAPH_OBJECT**. It stores the reference, not a copy of the vertex or edge.

The following query reads the first, second and last vertex of each path through **GRAPH_OBJECT** values, using the three ways to convert them:

```sql
SELECT property_of(CAST(first(nodes(pth)) AS GRAPH_OBJECT), name, product) AS product,
       property_of(at(CAST(nodes(pth) AS SEQUENCE(GRAPH_OBJECT)), 1), company_name, customer) AS liked_by,
       property_of(last(list_comp(x IN nodes(pth) | CAST(x AS GRAPH_OBJECT))), name, product) AS also_liked
FROM MATCH pth = (p1:product)-[l:likes{2,2}]-(p2:product)
WHERE p1.name = 'Vegie-spread' AND p1 <> p2
ORDER BY 2, 3
LIMIT 2;
```

| product | liked_by | also_liked |
|---|---|---|
| Vegie-spread | Alvarado LLC | Lono Yoga Short |
| Vegie-spread | Alvarado LLC | Neve Studio Dance Jacket |

> **Note:**
> `property_of()` must be given the table of the element at that position. In a path that mixes vertex tables (here `product`, `customer`, `product`), read each position with its own table rather than applying one table to every element.


> **See also:**
> - [MATCH](https://www.coradb.ai/manual/graph/match.html): graph patterns and path variables
> - [Graph functions](https://www.coradb.ai/manual/sql/function/graph_fn.html): [nodes()](https://www.coradb.ai/manual/sql/function/graph_fn.html#nodes), [relationships()](https://www.coradb.ai/manual/sql/function/graph_fn.html#relationships), [path_size()](https://www.coradb.ai/manual/sql/function/graph_fn.html#path_size), [path_comp()](https://www.coradb.ai/manual/sql/function/graph_fn.html#path_comp)
> - [List functions](https://www.coradb.ai/manual/sql/function/list_fn.html): [first()](https://www.coradb.ai/manual/sql/function/list_fn.html#first), [last()](https://www.coradb.ai/manual/sql/function/list_fn.html#last), [at()](https://www.coradb.ai/manual/sql/function/list_fn.html#at), [size()](https://www.coradb.ai/manual/sql/function/list_fn.html#size), [list_comp()](https://www.coradb.ai/manual/sql/function/list_fn.html#list_comp)
> - [PROPERTY_OF](https://www.coradb.ai/manual/sql/function/information_fn.html#fn-property-of)
