# 6.6.1 SELECT

Part of: [6 Language](6-language.md) › [6.6 Data Query Language (DQL)](6-6-data-query-language-dql.md)

### Syntax

**SELECT** [**DIRECTLY**] **FROM** [**DATASET** | **ATTRIBUTE**] [_file_name_] _object_name_ [**[**_selection_**]**]\
[**IN** **PARALLEL** [**NO** **VALUES**]]\
[**CACHE** [**SLOTS** {_slots_value_ | **FILE** | **DEFAULT**}] [**SIZE** {_size_value_ | **FILE** | **DEFAULT**}] [**PREEMPTION** {_preemption_value_ | **FILE** | **DEFAULT**}]]\
[_post_processing_option_]\
[_output_redirecting_option_]\
_selection_ := _hyperslab_ | _point_ | _chunk_\
_hyperslab_ := [_start_]**:**[_stride_]**:**[_count_]**:**[_block_] [**,** [_start_]**:**[_stride_]**:**[_count_]**:**[_block_]]\* [{**OR** | **AND** | **XOR** | **NOTA** | **NOTB**} [_start_]**:**[_stride_]**:**[_count_]**:**[_block_] [**,** [_start_]**:**[_stride_]**:**[_count_]**:**[_block_]]\*]\*\
_point_ := _coord_ [**,** _coord_]\* [**;** _coord_ [**,** _coord_]\*]\*\
_chunk_ := _chunk_number_ [**,** _chunk_number_]\*

### Description

Select (i.e. read) data from an HDF5 dataset or attribute named _object_name_. In case the keyword CACHE is specified, the dataset is read using a cache parameterized with the values _slots_value_, _size_value_, and _preemption_value_ (instead of the dataset cache parameters that may have been set through the operation [SET CACHE](6-8-11-set-cache.md)). In case a dataset and an attribute with identical names (_object_name_) are stored in the same location (i.e. group) and neither the keyword DATASET nor ATTRIBUTE is specified, the object from which data will be read is the dataset. To explicitly read data from an object according to its type, the keyword DATASET or ATTRIBUTE must be specified.

In case the keyword DIRECTLY[^42] is specified, HDFql reads data chunks directly from a dataset bypassing several internal processing steps of the HDF5 library itself (e.g. data conversion, filter pipeline), which can lead to much faster reading.

By default, the entire _object_name_ is read when performing a select operation. To read only a slice (i.e. portion) of _object_name_, hyperslab and point selections can be used[^43]. To enable a (regular) hyperslab selection, the _start_, _stride_, _count_, and _block_ parameters may be specified and separated with a colon (:). For each dimension of _object_name_, a set of such parameters may be specified, and each set should be separated with a comma (,). Multiple hyperslab selections can be enabled at once (in this case, the hyperslab will be considered irregular). This is achieved by using the following boolean operators:

- OR – adds the new selection to the existing selection.
- AND – retains only the overlapping portions of the new selection and the existing selection.
- XOR – retains only the elements that belong to either the new selection or the existing selection, excluding elements that belong to both selections.
- NOTA – retains only the elements of the new selection that are not in the existing selection.
- NOTB – retains only the elements of the existing selection that are not in the new selection.

To enable a point selection, a set of coordinates may be specified. Each coordinate is separated with a comma (,). More than one set of coordinates (i.e. points) may be specified, and each set should be separated with a semicolon (;). Of note, hyperslab and point selections cannot be used simultaneously (i.e. mixed) in a select operation. Since hyperslab and point selections can be complicated to set up, it is recommended to first read <https://support.hdfgroup.org/documentation/hdf5/latest/_h5_s__u_g.html> and, eventually, enable the debug mechanism (through the operation [SET DEBUG](6-8-20-set-debug.md)) when working with these, to obtain debug information in case of errors.

In case the keyword IN PARALLEL[^44] [^45] is specified, HDFql reads data from a dataset in parallel using all the processes associated with the default MPI communicator (MPI_COMM_WORLD) or with a user-defined MPI communicator (that may have been set through the function [hdfql_mpi_use_communicator](5-2-60-hdfql-mpi-use-communicator.md)). Of note, a dataset may only be read in parallel if the HDF5 file was opened in parallel in the first place (please refer to the operation [USE FILE](6-8-2-use-file.md) for additional information). In case the keyword NO VALUES is specified, no data is actually read by the MPI process in question (which may be useful in certain situations), only forcing it to participate in the operation (as, when working in parallel, it is mandatory that all MPI processes work collectively).

HDFql provides several ways of writing result sets that were read from a dataset or attribute, namely either to a cursor (e.g. “_SELECT FROM my_dataset_”) or to an output redirecting option (e.g. “_SELECT FROM my_dataset INTO FILE my_file.txt_”).

### Parameter(s)

_file_name_ – optional string that specifies the name of the HDF5 file storing the HDF5 dataset or attribute whose data is to be selected (i.e. read). If _file_name_ is specified, the file is opened on the fly, the data is selected from the dataset or attribute, and the file is subsequently closed. If not specified, the file currently in use is used instead.

_object_name_ – mandatory string that specifies the name of the HDF5 dataset or attribute to select (i.e. read) data from.

_start_ – optional integer that specifies the starting location of the hyperslab selection. If not specified, its default value is zero (i.e. the first position of the dimension in question). If negative, its value will be the last position of the dimension in question minus the absolute value of _start_.

_stride_ – optional integer that specifies the number of elements to separate each block to be selected. If not specified, its default value is equal to the value of _block_.

_count_ – optional integer that specifies the number of blocks to select along each dimension. If not specified, its default value is one.

_block_ – optional integer that specifies the size of the block selected (i.e. number of elements) from the HDF5 dataset. If not specified, its default value is the size of the dimension in question minus the absolute value of _start_, divided by the value of _count_.

_coord_ – optional integer that specifies the point of interest (i.e. the point at which to select data) for the point selection. If negative, its value will be the last position of the dimension in question minus the absolute value of _coord_.

_chunk_number_ – optional integer that specifies the number of the chunk to select (i.e. read) data from. If _chunk_number_ is specified, it must either be between 0 and the storage dimension in question - 1 (otherwise an error is raised) or negative (in this case, its value will be the last position of the storage dimension in question minus the absolute value of _chunk_number_). If not specified and in case the keyword DIRECTLY is specified, its default value is zero (i.e. first chunk of the storage dimension in question).

_slots_value_ – optional integer that specifies the number of chunk slots in the raw data chunk cache for accessing the HDF5 dataset. If _slots_value_ is specified, it must be equal to or greater than zero (otherwise an error is raised). Due to the hashing strategy, its value should ideally be a prime number. In case the keyword FILE is specified, its value will be as defined in the cache slots parameter upon using (i.e. opening) the file. In case the keyword DEFAULT is specified, its value is 521 (i.e. default value defined by the HDF5 library). In case the keyword SLOTS is not specified, its current value remains intact. Of note, if _object_name_ is an HDF5 attribute then the cache is ignored (i.e. has no effect).

_size_value_ – optional integer that specifies the total size of the raw data chunk cache in bytes for accessing the HDF5 dataset. If _size_value_ is specified, it must be equal to or greater than zero (otherwise an error is raised). In case the keyword FILE is specified, its value will be as defined in the cache size parameter upon using (i.e. opening) the file. In case the keyword DEFAULT is specified, its value is 1048576 (i.e. 1 MB – default value defined by the HDF5 library). In case the keyword SIZE is not specified, its current value remains intact. Of note, if _object_name_ is an HDF5 attribute then the cache is ignored (i.e. has no effect).

_preemption_value_ – optional float that specifies the chunk preemption policy for accessing the HDF5 dataset. If _preemption_value_ is specified, it must be between 0 and 1 (otherwise an error is raised). It indicates the weighting according to which chunks that have been fully read or written are penalized when determining which chunks to flush from cache. In case the keyword FILE is specified, its value will be as defined in the cache preemption parameter upon using (i.e. opening) the file. In case the keyword DEFAULT is specified, its value is 0.75 (i.e. default value defined by the HDF5 library). In case the keyword PREEMPTION is not specified, its current value remains intact. Of note, if _object_name_ is an HDF5 attribute then the cache is ignored (i.e. has no effect).

_post_processing_option_ – optional option that transforms the result set according to the programmer’s needs, such as ordering or truncating (please refer to the section [PROCESSING](6-2-processing.md) for additional information).

_output_redirecting_option_ – optional option that specifies the cursor in use, an HDF5 object (i.e. dataset or attribute), a (text, binary, or Excel) file, or memory (i.e. user-defined variable) to write the result set into (please refer to the subsection [INTO](6-3-2-into.md) for additional information). If not specified, the cursor in use is populated with the result set instead (please refer to the chapter [CURSOR](4-cursor.md) for additional information).

### Return

The data selected (i.e. read) from an HDF5 dataset or attribute as an [HDFQL_TINYINT](5-1-constants.md#hdfql_tinyint) (in case the data type of the dataset or attribute is [HDFQL_TINYINT](5-1-constants.md#hdfql_tinyint)), [HDFQL_UNSIGNED_TINYINT](5-1-constants.md#hdfql_unsigned_tinyint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_TINYINT](5-1-constants.md#hdfql_unsigned_tinyint)), [HDFQL_SMALLINT](5-1-constants.md#hdfql_smallint) (in case the data type of the dataset or attribute is [HDFQL_SMALLINT](5-1-constants.md#hdfql_smallint)), [HDFQL_UNSIGNED_SMALLINT](5-1-constants.md#hdfql_unsigned_smallint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_SMALLINT](5-1-constants.md#hdfql_unsigned_smallint)), [HDFQL_INT](5-1-constants.md#hdfql_int) (in case the data type of the dataset or attribute is [HDFQL_INT](5-1-constants.md#hdfql_int)), [HDFQL_UNSIGNED_INT](5-1-constants.md#hdfql_unsigned_int) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_INT](5-1-constants.md#hdfql_unsigned_int)), [HDFQL_BIGINT](5-1-constants.md#hdfql_bigint) (in case the data type of the dataset or attribute is [HDFQL_BIGINT](5-1-constants.md#hdfql_bigint)), [HDFQL_UNSIGNED_BIGINT](5-1-constants.md#hdfql_unsigned_bigint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_BIGINT](5-1-constants.md#hdfql_unsigned_bigint)), [HDFQL_FLOAT](5-1-constants.md#hdfql_float) (in case the data type of the dataset or attribute is [HDFQL_FLOAT](5-1-constants.md#hdfql_float)), [HDFQL_DOUBLE](5-1-constants.md#hdfql_double) (in case the data type of the dataset or attribute is [HDFQL_DOUBLE](5-1-constants.md#hdfql_double)), [HDFQL_CHAR](5-1-constants.md#hdfql_char) (in case the data type of the dataset or attribute is [HDFQL_CHAR](5-1-constants.md#hdfql_char)), [HDFQL_VARTINYINT](5-1-constants.md#hdfql_vartinyint) (in case the data type of the dataset or attribute is [HDFQL_VARTINYINT](5-1-constants.md#hdfql_vartinyint)), [HDFQL_UNSIGNED_VARTINYINT](5-1-constants.md#hdfql_unsigned_vartinyint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_VARTINYINT](5-1-constants.md#hdfql_unsigned_vartinyint)), [HDFQL_VARSMALLINT](5-1-constants.md#hdfql_varsmallint) (in case the data type of the dataset or attribute is [HDFQL_VARSMALLINT](5-1-constants.md#hdfql_varsmallint)), [HDFQL_UNSIGNED_VARSMALLINT](5-1-constants.md#hdfql_unsigned_varsmallint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_VARSMALLINT](5-1-constants.md#hdfql_unsigned_varsmallint)), [HDFQL_VARINT](5-1-constants.md#hdfql_varint) (in case the data type of the dataset or attribute is [HDFQL_VARINT](5-1-constants.md#hdfql_varint)), [HDFQL_UNSIGNED_VARINT](5-1-constants.md#hdfql_unsigned_varint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_VARINT](5-1-constants.md#hdfql_unsigned_varint)), [HDFQL_VARBIGINT](5-1-constants.md#hdfql_varbigint) (in case the data type of the dataset or attribute is [HDFQL_VARBIGINT](5-1-constants.md#hdfql_varbigint)), [HDFQL_UNSIGNED_VARBIGINT](5-1-constants.md#hdfql_unsigned_varbigint) (in case the data type of the dataset or attribute is [HDFQL_UNSIGNED_VARBIGINT](5-1-constants.md#hdfql_unsigned_varbigint)), [HDFQL_VARFLOAT](5-1-constants.md#hdfql_varfloat) (in case the data type of the dataset or attribute is [HDFQL_VARFLOAT](5-1-constants.md#hdfql_varfloat)), [HDFQL_VARDOUBLE](5-1-constants.md#hdfql_vardouble) (in case the data type of the dataset or attribute is [HDFQL_VARDOUBLE](5-1-constants.md#hdfql_vardouble)), [HDFQL_VARCHAR](5-1-constants.md#hdfql_varchar) (in case the data type of the dataset or attribute is [HDFQL_VARCHAR](5-1-constants.md#hdfql_varchar)), [HDFQL_OPAQUE](5-1-constants.md#hdfql_opaque) (in case the data type of the dataset or attribute is [HDFQL_OPAQUE](5-1-constants.md#hdfql_opaque)), [HDFQL_ENUMERATION](5-1-constants.md#hdfql_enumeration) (in case the data type of the dataset or attribute is [HDFQL_ENUMERATION](5-1-constants.md#hdfql_enumeration)), or [HDFQL_COMPOUND](5-1-constants.md#hdfql_compound) (in case the data type of the dataset or attribute is [HDFQL_COMPOUND](5-1-constants.md#hdfql_compound)).

### Example(s)

```hdfql
# create an HDF5 dataset named "my_dataset0" of data type short of one dimension (size 3) with initial values of 65, 66, and 77
CREATE DATASET my_dataset0 AS SMALLINT(3) VALUES(65, 66, 67)

# select (i.e. read) data from dataset "my_dataset0" and populate cursor in use with it (should return 65, 66, 67)
SELECT FROM my_dataset0

# create an HDF5 attribute named "my_attribute0" of data type short 
CREATE ATTRIBUTE my_attribute0 AS SMALLINT

# select (i.e. read) data from attribute "my_attribute0" and populate cursor in use with it (should return 0)
SELECT FROM my_attribute0

# create an HDF5 attribute named "my_attribute1" of data type unsigned short of one dimension (size 2) with initial values of 95 and 97
CREATE ATTRIBUTE my_attribute1 AS UNSIGNED SMALLINT(2) VALUES(95, 97)

# select (i.e. read) data from attribute "my_attribute1" and populate cursor in use with it (should return 95, 97)
SELECT FROM my_attribute1
```

```hdfql
# create an HDF5 dataset named "my_dataset1" of data type float of one dimension (size 512) 
CREATE DATASET my_dataset1 AS FLOAT(512)

# select (i.e. read) data from dataset "my_dataset1" and write it into a text file named "my_file0.txt" using default separator ","
SELECT FROM my_dataset1 INTO FILE my_file0.txt

# select (i.e. read) data from dataset "my_dataset1" and write it into a text file named "my_file1.txt" using a DOS-based end-of-line (EOL) terminator and separator "**"
SELECT FROM my_dataset1 INTO DOS TEXT FILE my_file1.txt SEPARATOR **

# select (i.e. read) data from dataset "my_dataset1" and write it into a binary file named "my_file.bin"
SELECT FROM my_dataset1 INTO BINARY FILE my_file.bin
```

```hdfql
# create an HDF5 dataset named "my_dataset2" of data type short of one dimension (size 5) 
CREATE DATASET my_dataset2 AS SMALLINT(5)

# insert (i.e. write) values 0, 5, 3, 9, and 7 into dataset "my_dataset2" 
INSERT INTO my_dataset2 VALUES(0, 5, 3, 9, 7)

# select (i.e. read) data from dataset "my_dataset2" using a hyperslab selection (starting from position #3) and populate cursor in use with it (should populate with 9, 7)
SELECT FROM my_dataset2[3:::]

# select (i.e. read) data from dataset "my_dataset2" using a hyperslab selection (starting from position #4) and populate cursor in use with it (should populate with 7)
SELECT FROM my_dataset2[-1:::]

# select (i.e. read) data from dataset "my_dataset2" using a hyperslab selection (starting from position #1 with a block of 2) and populate cursor in use with it (should populate with 5, 3)
SELECT FROM my_dataset2[1:::2]

# create an HDF5 dataset named "my_dataset3" of data type int of two dimensions (size 3x3) 
CREATE DATASET my_dataset3 AS INT(3, 3)

# insert (i.e. write) values 0, 0, 0, 0, 0, 0, 4, 8, and 6 into dataset "my_dataset3" 
INSERT INTO my_dataset3 VALUES(0, 0, 0, 0, 0, 0, 4, 8, 6)

# select (i.e. read) data from dataset "my_dataset3" using a hyperslab selection (starting from position #2 of the first dimension and position #1 of the second dimension) and populate cursor in use with it (should populate with 8, 6)
SELECT FROM my_dataset3[2:::, 1:::]

# select (i.e. read) data from dataset "my_dataset3" using a hyperslab selection (starting from position #2 of the first dimension and position #0 of the second dimension with a stride of 2, count of 2, and block of 1) and populate cursor in use with it (should populate with 4, 6)
SELECT FROM my_dataset3[2:::, 0:2:2:1]

# create an HDF5 dataset named "my_dataset4" of data type short of one dimension (size 10) 
CREATE DATASET my_dataset4 AS SMALLINT(10)

# insert (i.e. write) values 0, 0, 90, 91, 92, 93, 0, 94, 95, and 0 into dataset "my_dataset4"
INSERT INTO my_dataset4 VALUES(0, 0, 90, 91, 92, 93, 0, 94, 95, 0)

# select (i.e. read) data from dataset "my_dataset4" using an irregular hyperslab selection (starting from position #2 with a count of 3 and block of 1; starting from position #4 with a count of 2 and block of 1; starting from position #7 with a count of 2 and block of 1) and populate cursor in use with it (should populate with 90, 91, 92, 93, 94, 95)
SELECT FROM my_dataset4[2::3:1 OR 4::2:1 OR 7::2:1]

# create an HDF5 dataset named "my_dataset5" of data type long long of one dimension (size 15)
CREATE DATASET my_dataset5 AS BIGINT(15)

# insert (i.e. write) values 0, 0, 0, 0, 0, 75, 77, 0, 0, 0, 0, 0, 0, 0, and 0 into dataset "my_dataset5"
INSERT INTO my_dataset5 VALUES(0, 0, 0, 0, 0, 75, 77, 0, 0, 0, 0, 0, 0, 0, 0)

# select (i.e. read) data from dataset "my_dataset5" using an irregular hyperslab selection (starting from position #3 with a count of 4 and block of 1; starting from position #5 with a count of 3 and block of 1) and populate cursor in use with it (should populate with 75, 77)
SELECT FROM my_dataset5[3::4:1 AND 5::3:1]

# create an HDF5 dataset named "my_dataset6" of data type float of one dimension (size 8) 
CREATE DATASET my_dataset6 AS FLOAT(8)

# insert (i.e. write) values 0, 0, 7.5, 0, 7.7, 0, 0, and 7.9 into dataset "my_dataset6" 
INSERT INTO my_dataset6 VALUES(0, 0, 7.5, 0, 7.7, 0, 0, 7.9)

# select (i.e. read) data from dataset "my_dataset6" using a point selection (positions #2, 
#4, and #7) and populate cursor in use with it (should populate with 7.5, 7.7, 7.9) 
SELECT FROM my_dataset6[2; 4; 7]

# create an HDF5 dataset named "my_dataset7" of data type double of two dimensions (size 4x3)
CREATE DATASET my_dataset7 AS DOUBLE(4, 3)

# insert (i.e. write) values 0, 0, 0, 0, 0, 15.2, 0, 0, 0, 18.5, 0, and 0 into dataset "my_dataset7"
INSERT INTO my_dataset7 VALUES(0, 0, 0, 0, 0, 15.2, 0, 0, 0, 18.5, 0, 0)

# select (i.e. read) data from dataset "my_dataset7" using a point selection (position #1 of the first dimension and position #2 of the second dimension, position #3 of the first dimension and position #0 of the second dimension) and populate cursor in use with it (should populate with 15.2, 18.5)
SELECT FROM my_dataset7[1, 2; 3, 0]

# use (i.e. open) an HDF5 file named "my_file.h5" 
USE FILE my_file.h5

# create an HDF5 dataset named "my_dataset8" of data type double in the HDF5 file currently in use (i.e. file "my_file.h5")
CREATE DATASET my_dataset8 AS DOUBLE

# insert (i.e. write) value 6.5 into dataset "my_dataset8" 
INSERT INTO my_dataset8 VALUES(6.5)

# select (i.e. read) data from dataset "my_dataset8" and populate cursor in use with it (should populate with 6.5)
SELECT FROM my_dataset8

# close HDF5 file currently in use (i.e. file "my_file.h5") 
CLOSE FILE 

# insert (i.e. write) value 3.2 into dataset "my_dataset8" in file "my_file.h5" 
INSERT INTO my_file.h5 my_dataset8 VALUES(3.2)

# select (i.e. read) data from dataset "my_dataset8" in file "my_file.h5" and populate cursor in use with it (should populate with 3.2)
SELECT FROM my_file.h5 my_dataset8
```

```hdfql
# create an HDF5 dataset named "my_dataset9" of data type enumeration composed of three members named "helium" (with value 0), "oxygen" (with value 1), and "argon" (with value 2)
CREATE DATASET my_dataset9 AS ENUMERATION(helium, oxygen, argon)

# insert (i.e. write) value 1 (i.e. "oxygen") into dataset "my_dataset9" 
INSERT INTO my_dataset9 VALUES(oxygen)

# select (i.e. read) data from dataset "my_dataset9" and populate cursor in use with it (should populate with 1 (i.e. "oxygen"))
SELECT FROM my_dataset9

# create an HDF5 attribute named "my_attribute2" of data type enumeration of one dimension (size 4) composed of three members named "red" (with value 0), "green" (with value 50), and "blue" (with value 51)
CREATE ATTRIBUTE my_attribute2 AS ENUMERATION(red, green AS 50, blue)(4)

# insert (i.e. write) values 51 (i.e. "blue"), "red" (i.e. 0), "green" (i.e. 50), and "blue" (i.e. 51) into attribute "my_attribute2"
INSERT INTO my_attribute2 VALUES(51, red, green, blue)

# select (i.e. read) data from attribute "my_attribute2" and populate cursor in use with it (should populate with 51 (i.e. "blue"), 0 (i.e. "red"), 50 (i.e. "green"), 51 (i.e. "blue"))
SELECT FROM my_attribute2

# create a chunked (size 2) HDF5 dataset named "my_dataset10" of data type int of one dimension (size 6)
CREATE CHUNKED(2) DATASET my_dataset10 AS INT(6)

# insert (i.e. write) values 60, 61, 62, 63, 64, and 65 into dataset "my_dataset10" 
INSERT INTO my_dataset10 VALUES(60, 61, 62, 63, 64, 65)

# select (i.e. read) data directly from chunk #0 of dataset "my_dataset10" (should return 60, 61)
SELECT DIRECTLY FROM my_dataset10

# select (i.e. read) data directly from chunk #1 of dataset "my_dataset10" (should return 62, 63)
SELECT DIRECTLY FROM my_dataset10[1]

# select (i.e. read) data directly from chunk #2 of dataset "my_dataset10" (should return 64, 65)
SELECT DIRECTLY FROM my_dataset10[2]
```

```c
// declare variables 
char script[1024];
double data[3]; 
int i;

// create an HDF5 dataset named "my_dataset11" of data type double of one dimension (size 3) with initial values of 21.1, 18.8, and 75.6
hdfql_execute("CREATE DATASET my_dataset11 AS DOUBLE(3) VALUES(21.1, 18.8, 75.6)");

// register variable "data" for subsequent use (by HDFql) 
hdfql_variable_register(data);

// prepare script to select (i.e. read) data from dataset "my_dataset11" and populate variable "data" with it
sprintf(script, "SELECT FROM my_dataset11 INTO MEMORY %d", hdfql_variable_get_number(data));

// execute script 
hdfql_execute(script);

// unregister variable "data" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(data); 

// display content of variable "data" (should be 21.1, 18.8, 75.6) 
for(i = 0; i < 3; i++)
{
    printf("%f\n", data[i]);
} 
```

```c
// declare variables 
char script[1024];
HDFQL_VARIABLE_LENGTH data[3];
int x; 
int y;
int count;

// create an HDF5 dataset named "my_dataset12" of data type variable-length double of one dimension (size 3)
hdfql_execute("CREATE DATASET my_dataset12 AS VARDOUBLE(3)");

// insert (i.e. write) values into dataset "my_dataset12" 
hdfql_execute("INSERT INTO my_dataset12 VALUES((3.2, 1.3), (0, 0.2), (9.1, 7.4, 6.5))");

// register variable "data" for subsequent use (by HDFql) 
hdfql_variable_register(data);

// prepare script to select (i.e. read) data from dataset "my_dataset12" and populate variable "data" with it
sprintf(script, "SELECT FROM my_dataset12 INTO MEMORY %d", hdfql_variable_get_number(data));

// execute script 
hdfql_execute(script);

// unregister variable "data" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(data); 

// display content of variable "data" (should be 3.2, 1.3, 0, 0.2, 9.1, 7.4, 6.5) 
for(x = 0; x < 3; x++)
{ 
    count = data[x].count;
    for(y = 0; y < count; y++)
    {
       printf("%f\n", *((double *) data[x].address + y));
    }
}

// release memory allocated (by HDFql) in variable "data" 
for(x = 0; x < 3; x++)
{ 
    free(data[x].address);
}
```

```c
// declare variables 
char script[1024];
char *data[3];
int x; 

// create an HDF5 dataset named "my_dataset13" of data type variable-length char of one dimension (size 3)
hdfql_execute("CREATE DATASET my_dataset13 AS VARCHAR(3)");

// insert (i.e. write) values into dataset "my_dataset13" 
hdfql_execute("INSERT INTO my_dataset13 VALUES(\"Hierarchical\", \"Data\", \"Format\")");

// register variable "data" for subsequent use (by HDFql) 
hdfql_variable_register(data);

// prepare script to select (i.e. read) data from dataset "my_dataset13" and populate variable "data" with it
sprintf(script, "SELECT FROM my_dataset13 INTO MEMORY %d", hdfql_variable_get_number(data));

// execute script 
hdfql_execute(script);

// unregister variable "data" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(data); 

// display content of variable "data" (should be "Hierarchical", "Data", "Format") 
for(x = 0; x < 3; x++)
{ 
    printf("%s\n", data[x]);
}

// release memory allocated (by HDFql) in variable "data" 
for(x = 0; x < 3; x++)
{ 
    free(data[x]);
}
```

```c
// declare structure 
struct coordinate
{
   double latitude; 
   double longitude; 
};

// declare variables 
char script[1024];
struct coordinate location;

// create an HDF5 attribute named "my_attribute3" of data type compound composed of two members named "latitude" (of data type double) and "longitude" (of data type double), and with initial values of 15.9803486587 for member "latitude" and 48.6352028395 for member "longitude"
hdfql_execute("CREATE ATTRIBUTE my_attribute3 AS COMPOUND(latitude AS DOUBLE, longitude AS DOUBLE) VALUES(15.9803486587, 48.6352028395)");

// prepare script to select (i.e. read) data from dataset "my_attribute3" and populate variable "location" with it
sprintf(script, "SELECT FROM my_attribute3 INTO MEMORY %d", hdfql_variable_transient_register(&location));

// execute script 
hdfql_execute(script); 

// display content of variable "location" (should be "Latitude is 15.9803486587 and longitude is 48.6352028395")
printf("Latitude is %f and longitude is %f\n", location.latitude, location.longitude);
```

```c
// declare structure 
struct data
{ 
   char description[7]; 
   int index; 
};

// declare variables 
char script[1024];
struct data cities[3]; 
int number; 
int i;

// create an HDF5 dataset named "my_dataset14" of data type compound of one dimension (size 3) composed of two members named "description" (of data type char) and "index" (of data type int), and with initial values of "Toronto" and 10 for the first position, "Nairobi" and 12 for the second position, and "Caracas" and 11 for the third position
hdfql_execute("CREATE DATASET my_dataset14 AS COMPOUND(description AS CHAR(7), index AS INT)(3) VALUES((Toronto, 10), (Nairobi, 12), (Caracas, 11))");

// register variable "cities" for subsequent use (by HDFql) 
number = hdfql_variable_register(cities);

// prepare script to select (i.e. read) data from dataset "my_dataset14" and populate variable "cities" with it
sprintf(script, "SELECT FROM my_dataset14 INTO MEMORY %d SIZE %d OFFSET(%d, %d)", number, sizeof(struct data), offsetof(struct data, description), offsetof(struct data, index));

// execute script 
hdfql_execute(script); 

// unregister variable "cities" as it is no longer used/needed (by HDFql) 
hdfql_variable_unregister(cities); 

// display content of variable "cities" (should be "The city of Toronto has index 10", "The city of Nairobi has index 12", "The city of Caracas has index 11")
for(i = 0; i < 3; i++)
{
    printf("The city of %s has index %d\n", cities[i].description, cities[i].index);
}
```

```c
// assume that (1) the following program is launched in parallel using four MPI processes (e.g. "mpiexec -n 4 ./my_program"), (2) an HDF5 file named "my_file.h5" containing a dataset named "my_dataset15" of data type int of one dimension (size 4) already exists, and (3) the dataset stores the values 0, 10, 20, and 30 in positions #0, #1, #2, and #3, respectively

// declare variables 
char script[1024]; 
int rank;

// use (i.e. open) an HDF5 file named "my_file.h5" in parallel 
hdfql_execute("USE FILE my_file.h5 IN PARALLEL");

// get rank of the MPI process (should be between 0 and 3) 
rank = hdfql_mpi_get_rank();

// prepare script to select (i.e. read) in parallel positions #0 (by MPI process rank 0), #1 (by MPI process rank 1), #2 (by MPI process rank 2), and #3 (by MPI process rank 3) from dataset "my_dataset15" using a point selection
sprintf(script, "SELECT FROM my_dataset15[%d] IN PARALLEL", rank); 

// execute script 
hdfql_execute(script); 

// move the cursor in use to the first position within the result set 
hdfql_cursor_first(NULL); 

// display value selected (i.e. read) by each MPI process (should display message "Value read by MPI process rank X is Y" four times, where X is 0 and Y is 0, X is 1 and Y is 10, X is 2 and Y is 20, or X is 3 and Y is 30 (not necessarily in this order))
printf("Value read by MPI process rank %d is %d\n", rank, *hdfql_cursor_get_int(NULL)); 
```

[^42]: Only available for HDF5 datasets as, by design, direct selection (i.e. read) for HDF5 attributes is not supported by the HDF5 library. Moreover, the library does not support reading data directly from a dataset of data type variable-length or compound with a member of data type variable-length.
[^43]: Only available for HDF5 datasets as, by design, neither hyperslab nor point selections for HDF5 attributes are supported by the HDF5 library.
[^44]: This option is not allowed on Windows as HDFql does not currently support the parallel HDF5 (PHDF5) library on this platform.
[^45]: Only available for HDF5 datasets as, by design, selecting (i.e. reading) data from HDF5 attributes is not supported in parallel. Moreover, the library does not support reading data from a dataset of data type variable-length or compound with a member of data type variable-length in parallel.
