How do I change CockroachDB's default database?
Asked Answered
S

1

6

When I connect to CockroachDB using cockroach sql, I have to prefix all table names with the name of the database:

SELECT * FROM db.table1;

If I forget to specify the database, like

SELECT * FROM table1;

I get the error pq: table "table1" does not exist.

Shibboleth answered 10/4, 2017 at 19:35 Comment(0)
S
10

You can set the database from an active SQL session by running:

SET DATABASE = [database]

You can also specify this when you connect by passing the --database argument to cockroach sql:

cockroach sql --database=[database]

Both of these are set per-session, so you’ll need to use them every time you connect.

If using a connection string, you can specify the database as the path segment of the URL, e.g.:

postgresql://root@localhost:26257/[database]
Shibboleth answered 10/4, 2017 at 19:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.