Logo

dev-resources.site

for different kinds of informations.

Composite Data types part 1

Published at
6/10/2023
Categories
apache
postgressql
json
datatypes
Author
talhahahae
Categories
4 categories in total
apache
open
postgressql
open
json
open
datatypes
open
Author
10 person written this
talhahahae
open
Composite Data types part 1

Composite Data types:

In this article we will discuss the composite datatypes in Apache age. Following are some of the composite data types in age with example queries.

List:

A literal list is created using brackets and separating the elements in the list with commas. A list can also hole null values, unlike when a null is an independent value, it will appear as the word null in a list.

Query:

The below query returns the list

SELECT *
FROM cypher('graph_name', $$
    WITH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst
$$) AS (lst agtype);
Enter fullscreen mode Exit fullscreen mode

Using null in the query:
It will return the list containing null.

SELECT *
FROM cypher('graph_name', $$
    WITH [null] as lst
    RETURN lst
$$) AS (lst agtype);
Enter fullscreen mode Exit fullscreen mode

Accessing elements:

To access individual elements in the list, we use the square brackets again. This will extract from the start index and move up to but not till the end index.
The below query will return the 3rd element of the list.

SELECT *
FROM cypher('graph_name', $$
    WITH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst[3]
$$) AS (element agtype);
Enter fullscreen mode Exit fullscreen mode

Map elements in the list:

You can also contains map elements in the list like below:

SELECT *
FROM cypher('graph_name', $$
   WITH [0, {status: 'teacher'}, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst
$$) AS (map_value agtype);
Enter fullscreen mode Exit fullscreen mode

In order to access such map elements you can access them using the key attribute of that map. For example below code will output the value of status which is teacher here.

SELECT *
FROM cypher('graph_name', $$
   WITH [0, {status: 'teacher'}, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst[1].status
$$) AS (map_value agtype);
Enter fullscreen mode Exit fullscreen mode

Negative index access:

You can use negative numbers as index which will start from the end of the list.

SELECT *
FROM cypher('graph_name', $$
    WITH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst[-3]
$$) AS (element agtype);
Enter fullscreen mode Exit fullscreen mode

Above query will return the 3rd item from the end of the list i.e. 8

Index ranges:

You can also indicate ranges inside the brackets to return item in that range of the list.

SELECT *
FROM cypher('graph_name', $$
    WITH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst[0..3]
$$) AS (element agtype);
Enter fullscreen mode Exit fullscreen mode

Above query will return elements at index 0, 1 and 2.

Negative index ranges:

You can also use negative ranges in the indexes. For example the below query will print the first 5 elements in the list.

SELECT *
FROM cypher('graph_name', $$
    WITH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst[0..-5]
$$) AS (lst agtype);
Enter fullscreen mode Exit fullscreen mode

Positive Slices:

The positive slices can be used to obtain the number of elements in the list. The below query will print first 4 elements in the list.

SELECT *
FROM cypher('graph_name', $$
    WITH [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] as lst
    RETURN lst[..4]
$$) AS (lst agtype);
Enter fullscreen mode Exit fullscreen mode

References:

You can follow for more content on age website and github:

  1. Apache age
  2. Apache age Github
datatypes Article's
30 articles in total
Favicon
14. Longest Common Prefix - Using Trie
Favicon
Variables & Data types
Favicon
Handling Data in SQL: Signed vs. Unsigned Types
Favicon
Representação numérica na computação
Favicon
Understanding Floats in Python: Essential Tips and Examples
Favicon
Everything You Need to Know About Python Integers: Tips, Tricks, and Examples
Favicon
Understanding Python Data Types: A Comprehensive Guide
Favicon
Why I Revisited MS SQL Server Basics: A Deep Dive into String Data Types
Favicon
Understanding Data Types in JavaScript
Favicon
Disjoint Unions in C
Favicon
PYTHON-FUNDAMENTALS: CONSTANTS, VARIABLES AND DATA TYPES
Favicon
Understanding Your Data: The Essentials of Exploratory Data Analysis"
Favicon
Data Types of Typescript
Favicon
C# {Data Types except Int}
Favicon
Variables, Constants, Data Types, and Namespaces in C++
Favicon
Data Types in Python
Favicon
JS Data types (Ma'lumot turlari)
Favicon
Data Types
Favicon
C# da ratsional sonlar bilan ishlovchi (float, double, decimal) ma'lumot turlari
Favicon
Big Integer in Java
Favicon
Oracle Data Types: An Overview
Favicon
Understanding Float vs. Double in C and C++
Favicon
Data Types - Python
Favicon
The Art of Series Summation in C: Navigating Data Types, Casting Magic, and the Dance of Incrementation
Favicon
Understanding Why We Don't Use Pointers to change the value of the element in Slice Data Type in Go Lang!
Favicon
A step by step guide to Converting a Column to Date Data Type in a Dataset using R
Favicon
Choosing the Right Java Data Types
Favicon
Evolution of Ruby Data Types
Favicon
Composite Data types part 1
Favicon
Network Address Types in PostgreSQL. Why you need to know?

Featured ones: