SQL Shell

On this page Carat arrow pointing down
Note:

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

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.

  1. 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:

    icon/buttons/copy
    > CREATE TABLE dogs (
        id INT PRIMARY KEY,
        name STRING
    );
    
  2. 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:

    icon/buttons/copy
    > INSERT INTO dogs VALUES (1, 'Petee'), (2, 'Carl');
    
  3. Click the copy icon next to the successful INSERT INTO statement, paste it into the input field, edit the values, and run it again:

    icon/buttons/copy
    > INSERT INTO dogs VALUES (3, 'Blue'), (4, 'Clifford');
    
  4. 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:

    icon/buttons/copy
    > SELECT name FROM dogs;
    
         | name
    +----+----------+
       1 | Petee
       2 | Carl
       3 | Blue
       4 | Clifford
    
  5. Edit the executed SELECT statement to replace name with the * wildcard symbol and click Run:

    icon/buttons/copy
    > 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.

  6. Click Export results to download a CSV file of the output.

See also


Yes No
On this page

Yes No