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.

benesch
  • 5,239
  • 1
  • 22
  • 36

1 Answers1

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]
benesch
  • 5,239
  • 1
  • 22
  • 36