# Query · Chromia Docs (concept)

> Queries provide a controlled way to retrieve data in Rell.

Source: https://docs.chromia.com/rell/language-features/modules/query/

# Query

On this page

* [Short form](#short-form)
* [Full form](#full-form)
* [Size constraint annotations for parameters](#size-constraint-annotations-for-parameters)
* [Default parameter values](#default-parameter-values)

Queries provide a controlled way to retrieve data in Rell.

Queries have the following characteristics:

* Can't modify the data in the database (compile-time verification)
* Must return a value
* If the return type isn't explicitly specified, it's implicitly deducted
* Parameter types and return types must be GTV-compatible

### Short form

Compact syntax for straightforward queries:

Rell

```
query q(x: integer): integer = x * x;
```

### Full form

More explicit syntax with a `return` statement:

Rell

```
query q(x: integer): integer {
    return x * x;
}
```

## Size constraint annotations for parameters

Query parameters support size constraint annotations. Available annotations:

* **`@size(n)`** / **`@size(a, b)`**: Exact size or range (shorthand for `@min_size` and `@max_size`)
* **`@min_size(n)`**: Minimum size
* **`@max_size(n)`**: Maximum size

Supported types: [`text`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/text/) and
[`byte_array`](https://docs.chromia.com/pages/rell-stdlib/-rell-system-library/root/byte_array/). For examples
and details, see
[Size constraint annotations for parameters](https://docs.chromia.com/rell/language-features/modules/size-constraint-annotations/).

## Default parameter values

Queries can have parameters with default values, making them optional when called from the blockchain (external
clients). This allows you to add new parameters without breaking existing client code.

Rell

```
query get_users(min_age: integer = 0, max_age: integer = 100): list<user> {
    return user @* { .age >= min_age, .age <= max_age };
}
```

In this example, both `min_age` and `max_age` have default values, so they're optional when calling the query from the
blockchain. Clients can call `get_users` without any parameters, with just `min_age`, or with both parameters.

[View this page on docs.chromia.com](https://docs.chromia.com/rell/language-features/modules/query/)Content mirrored from the live docs
