[Yandex Cloud documentation](../../index.md) > [Yandex Query](../index.md) > Data sources and sinks > Working with Managed Service for YDB databases

# Working with Managed Service for YDB databases

This section covers the basics of working with [Managed Service for YDB](https://yandex.cloud/ru/services/ydb).

To start working with a Managed Service for YDB database, follow these steps:
1. Create a [connection](../concepts/glossary.md#connection) containing your database access credentials.
1. [Run a query](#query) against the database.

Query example for reading data from Managed Service for YDB:

```sql
SELECT * FROM ydb_connection.my_table
```

Where:
* `ydb_connection`: Your database connection name.
* `my_table`: Database table name.


## Setting up a connection {#create_connection}

To create a connection to Managed Service for YDB:

1. In the [management console](https://console.yandex.cloud), select the folder where you want to create a connection.
1. Navigate to **Yandex Query**.
1. In the left-hand panel, switch to the **Connections** tab.
1. Click ![info](../../_assets/console-icons/plus.svg) **Create new**.
1. Specify the connection settings:

   1. Under **General parameters**:

      * **Name**: Managed Service for YDB connection name.
      * **Type**: `Managed Service for YDB`.
   1. Under **Connection type parameters**:
      * **Cluster**: Select an existing Managed Service for YDB database or create a new one.
      * **Service account**: Select the Managed Service for YDB [service account](../../iam/concepts/users/service-accounts.md) you will use for `Managed Service for YDB` cluster connections and database authentication. If you do not have a service account, create one and assign the `ydb.viewer` [role](../../ydb/security/index.md#ydb-viewer) to it.

        To use a service account, the `iam.serviceAccounts.user` [role](../../iam/security/index.md#iam-serviceAccounts-user) is required.


1. Click **Create**.

## Query syntax {#query}

Managed Service for YDB uses the following SQL syntax:

```sql
SELECT * FROM <connection>.<table_name>
```

Where:
* `<connection>`: Your database connection name.
* `<table_name>`: Database table name.

## Limits {#limits}

External sources are available for read-only access via `SELECT` queries. Yandex Query does not currently support data-modifying queries against external sources.

## Filter pushdown {#predicate_pushdown}

Yandex Query can push parts of query processing down to the source data system by sending filter expressions, e.g., `WHERE` conditions, directly to the database. This approach is known as `filter pushdown`.

Filter pushdown is possible when using:

|Description|Example|Limitation|
|---|---|---|
|`IS NULL` and `IS NOT NULL` filters|`WHERE column1 IS NULL` or `WHERE column1 IS NOT NULL`||
|Logical operators `AND`, `OR`, `NOT`, and parentheses to control operator precedence |`WHERE column1 IS NULL OR (column2 IS NOT NULL AND column3 > 10)`.||
|Comparison operators `=`, `==`, `!=`, `<>`, `>`, `<`, `>=`, and `<=` that compare a column with other columns or constants|`WHERE column1 > column2 OR column3 <= 10`.||
|`LIKE` string pattern matching operator|`WHERE column1 LIKE '_abc%'`|Currently, filter pushdown only supports patterns based on prefixes, e.g., `'abc_'` or `'abc%'`, suffixes, e.g., `'_abc'` or `'%abc'`, and substring matches, e.g., `'_abc_'`, `'%abc%'`, `'_abc%'`, or `'%abc_'`. To push down more complex patterns, you can use the `REGEXP` operator.|
|`REGEXP` pattern-matching operator|`WHERE column1 REGEXP '.*abc.*'`||

Other filter types do not support source pushdown: the external table rows are filtered on the federated Yandex Query side, i.e., Yandex Query will perform a full scan of the external table when processing the query.

Supported data types for filter pushdown:

|Yandex Query data type|
|----|
|`Bool`|
|`Int8`|
|`Uint8`|
|`Int16`|
|`Uint16`|
|`Int32`|
|`Uint32`|
|`Int64`|
|`Uint64`|
|`Float`|
|`Double`|
|`String`|
|`Utf8`|

## Supported data types {#supported_types}

The tables below show type mapping between Managed Service for YDB and Yandex Query. Only the listed types are supported.

### Primitive data types {#supported_types_default}

| Managed Service for YDB data type | Yandex Query data type |
| :---: | :----: |
| `Bool` | `Bool` |
| `Int8` | `Int8` |
| `Uint8` | `Uint8` |
| `Int16` | `Int16` |
| `Uint16` | `Uint16` |
| `Int32` | `Int32` |
| `Uint32` | `Uint32` |
| `Int64` | `Int64` |
| `Uint64` | `Uint64` |
| `Float` | `Float` |
| `Double` | `Double` |
| `Date` | `Date` |
| `Datetime` | `Datetime` |
| `Timestamp` | `Timestamp` |
| `String` | `String` |
| `Utf8` | `Utf8` |
| `Json` | `Json` |
| `JsonDocument` | `Json` |

### Optional data types {#supported_types_nullable}

| Managed Service for YDB data type | Yandex Query data type |
| :---: | :----: |
| `Optional<Bool>` | `Optional<Bool>` |
| `Optional<Int8>` | `Optional<Int8>` |
| `Optional<Uint8>` | `Optional<Uint8>` |
| `Optional<Int16>` | `Optional<Int16>` |
| `Optional<Uint16>` | `Optional<Uint16>` |
| `Optional<Int32>` | `Optional<Int32>` |
| `Optional<Uint32>` | `Optional<Uint32>` |
| `Optional<Int64>` | `Optional<Int64>` |
| `Optional<Uint64>` | `Optional<Uint64>` |
| `Optional<Float>` | `Optional<Float>` |
| `Optional<Double>` | `Optional<Double>` |
| `Optional<Date>` | `Optional<Date>` |
| `Optional<Datetime>` | `Optional<Datetime>` |
| `Optional<Timestamp>` | `Optional<Timestamp>` |
| `Optional<String>` | `Optional<String>` |
| `Optional<Utf8>` | `Optional<Utf8>` |
| `Optional<Json>` | `Optional<Json>` |
| `Optional<JsonDocument>` | `Optional<Json>` |