# SELECT

> Switch the connection to another numbered logical database.

URL: https://docs.hotkv.com/commands/select/

```
SELECT index
```

- Group: Connection
- Complexity: O(1)
- HotKV Cloud: all plans
- On-Premise: no license needed

`SELECT` changes the logical database the current connection reads and
writes. Databases are numbered from `0`, and how many there are is set by the
`databases` setting (16 by default, changed only with a restart). A new
connection starts in database `0`. Other connections are not affected.

## Return value

| Case | Reply (RESP2 and RESP3) |
| --- | --- |
| Switched | Simple string `OK` |
| `index` is not an integer | Error `ERR value is not an integer or out of range` |
| `index` does not fit a 32-bit integer | Error `ERR value is out of range, value must between -2147483648 and 2147483647` |
| `index` is negative, or not below `databases` | Error `ERR DB index is out of range` |
| A non-zero `index` on a cluster node with the default `cluster-databases 1` | Error `ERR SELECT is not allowed in cluster mode` |
| An `index` not below `cluster-databases` on a cluster node with more databases | Error `ERR DB index is out of range` |

## Examples

```
127.0.0.1:6379> SET k "in db 0"
OK
127.0.0.1:6379> SELECT 3
OK
127.0.0.1:6379[3]> GET k
(nil)
127.0.0.1:6379[3]> SELECT 16
(error) ERR DB index is out of range
```

## Compatibility

Same replies as Redis 7. As in Redis Cluster, a cluster node has one database by
default and `SELECT 0` is accepted there. As in Valkey 9, the setting
`cluster-databases` (1 to 128, set at startup) gives a cluster node more
databases, and `SELECT` then works up to that number. See
[Databases in a cluster](https://docs.hotkv.com/clustering/keys-and-commands/index.md#databases).

## See also

[SWAPDB](https://docs.hotkv.com/commands/swapdb/index.md), [MOVE](https://docs.hotkv.com/commands/move/index.md),
[DBSIZE](https://docs.hotkv.com/commands/dbsize/index.md), [FLUSHDB](https://docs.hotkv.com/commands/flushdb/index.md),
[RESET](https://docs.hotkv.com/commands/reset/index.md)