> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mindsdb.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cloud Spanner

This is the implementation of the Cloud Spanner data handler for MindsDB.

[Cloud Spanner](https://cloud.google.com/spanner) is a fully managed, mission-critical, relational database service that offers transactional consistency at global scale, automatic, synchronous replication for high availability. It supports two SQL dialects: GoogleSQL (ANSI 2011 with extensions) and PostgreSQL.

## Prerequisites

Before proceeding, ensure the following prerequisites are met:

1. Install MindsDB locally via [Docker](/setup/self-hosted/docker) or [Docker Desktop](/setup/self-hosted/docker-desktop).
2. To connect Cloud Spanner to MindsDB, install the required dependencies following [this instruction](/setup/self-hosted/docker#install-dependencies).
3. Install or ensure access to Cloud Spanner.

## Implementation

This handler was implemented using the `google-cloud-spanner` Python client library.

The required arguments to establish a connection are as follows:

* `instance_id` is the instance identifier.
* `database_id` is the database identifier.
* `project` is the identifier of the project that owns the resources.
* `credentials` is a stringified GCP service account key JSON.

## Usage

In order to make use of this handler and connect to the Cloud Spanner database in MindsDB, the following syntax can be used:

```sql theme={null}
CREATE DATABASE cloud_spanner_datasource
WITH
    engine = 'cloud_spanner',
    parameters = {
      "instance_id": "my-instance",
      "database_id": "example-id",
      "project": "my-project",
      "credentials": "{...}"
    };
```

You can use this established connection to query your table as follows:

```sql theme={null}
SELECT *
FROM cloud_spanner_datasource.my_table;
```

<Note>
  Cloud Spanner supports both PostgreSQL and GoogleSQL dialects. However, not all PostgresSQL features are supported.
</Note>
