This feature is in preview. This feature is subject to change. To share feedback and/or issues, contact Support.
The SQL Shell page on the Console enables you to run queries on your cluster directly from your browser.
To use this feature, select a cluster from the Clusters page, and navigate to the cluster's SQL Shell page.
Limitations
- All statements in the SQL Shell are executed within a transaction, so you cannot use the SET CLUSTER SETTING statement to configure cluster settings.
- The SQL Shell does not yet support sessions.
- The SQL Shell is available to CockroachDB Cloud users with the Cluster Administrator role.
- The SQL Shell is not available by default for CockroachDB Dedicated advanced clusters. To get access to the SQL Shell for your CockroachDB Dedicated advanced cluster, contact us.
Overview
Above the SQL Shell input field, you will see the active user and cluster details in the format {user name} @ {cluster-name}:{active-database}
. Note that the user displayed is the Team member currently logged into the Cloud Console, not the active SQL user, which is root
. Team members without the Cluster Administrator role needed to access the Cloud Console SQL Shell can still access CockroachDB's command line SQL shell.
You can change the active database in the dropdown menu above the input field. If you create a new database in the SQL Shell, you will have to reload the page to refresh the database dropdown menu. Reloading the page will also clear your activity.
To execute a SQL statement, enter it in the input field and either click Run or use the Enter key. The statement status will be Loading until it either Succeeds or returns an Error. Any results returned can be exported by clicking the Export results button below the executed statement.
You can select any statement that you've previously run and copy it, edit it, or re-run it.
Example workflow
The following examples assume you have already created a CockroachDB Cloud cluster and have access to the SQL Shell.
In the SQL Shell, run
CREATE TABLE
followed by a table name, the column names, and the data type and constraint, if any, for each column:> CREATE TABLE dogs ( id INT PRIMARY KEY, name STRING );
Insert rows into the table using
INSERT INTO
followed by the table name and then the column values listed in the order in which the columns appear in the table:> INSERT INTO dogs VALUES (1, 'Petee'), (2, 'Carl');
Click the copy icon next to the successful
INSERT INTO
statement, paste it into the input field, edit the values, and run it again:> INSERT INTO dogs VALUES (3, 'Blue'), (4, 'Clifford');
Query the table with
SELECT
followed by a comma-separated list of the columns to be returned and the table from which to retrieve the data:> SELECT name FROM dogs;
| name +----+----------+ 1 | Petee 2 | Carl 3 | Blue 4 | Clifford
Edit the executed
SELECT
statement to replacename
with the*
wildcard symbol and click Run:> SELECT * FROM dogs;
| id | name +----+----------+ 1 | 1 | Petee 2 | 2 | Carl 3 | 3 | Blue 4 | 4 | Clifford
Note that each line of a query's results will be numbered independently of the output. This is for readability and will not be shown in any exported data.
Click Export results to download a CSV file of the output.