USE

Syntax

USE { DATABASE | ORGANIZATION | ROLE | SCHEMA | STORE } entity_name;

Description

This switches the current session’s Database, Organization, Role, Schema, or Store.

Arguments

entity_name

The name of an existing entity to set as the user’s current for the active session. Use SET DEFAULT to persist the change for new sessions. For case-sensitive names, the name must be wrapped in double quotes; otherwise, the lowercase name will be used.

When using a new Schema, a fully qualified Schema name can optionally be used to set the current Database and Schema.

Examples

Use a new Database

In the following example, we are creating a new Database called demodb2 and using it. Note the Database in the command line prompt changing from demodb to demodb2:

demodb.public/demostore# CREATE DATABASE demodb2;
demodb.public/demostore# LIST DATABASES;

   Name   | Default |  Owner   |      Created at      |      Updated at
----------+---------+----------+----------------------+-----------------------
  demodb  |        | sysadmin | 2022-08-22T17:01:02Z | 2022-08-22T17:01:02Z
  demodb2 |         | sysadmin | 2022-08-22T18:20:07Z | 2022-08-22T18:20:07Z

demodb.public/demostore# USE DATABASE demodb2;
demodb2.public/demostore#

Use a new Schema

In the following example, we are switching from the current public Schema to use a new Schema called newschema. Note how after the command is issued, the default Schema changes:

demodb.public/demostore# LIST SCHEMAS;

     Name    | Default |  Owner   |      Created at      |      Updated at
-------------+---------+----------+----------------------+-----------------------
  public     |        | sysadmin | 2022-08-22T17:01:02Z | 2022-08-22T17:01:02Z
  newschema  |         | sysadmin | 2022-08-22T17:01:02Z | 2022-08-22T17:01:02Z

demodb.public/demostore# USE SCHEMA newschema;
demodb.newschema/demostore# LIST SCHEMAS;

     Name    | Default |  Owner   |      Created at      |      Updated at
-------------+---------+----------+----------------------+-----------------------
  public     |         | sysadmin | 2022-08-22T17:01:02Z | 2022-08-22T17:01:02Z
  newschema  |        | sysadmin | 2022-08-22T17:01:02Z | 2022-08-22T17:01:02Z

Use a new Store

The following shows how a new Demostore2 Store is created and set as the current Store to use:

demodb.public/demostore# CREATE STORE "Demostore2" WITH ('type' = KAFKA, 'access_region' = "AWS us-east-1", 'tls.ca_cert_file' = 'kafka-ca.crt', 'uris' = 'kafka.kafka.svc:9092' );
demodb.public/demostore# LIST STORES;

     Name    | Kind  | Availability zone | Metadata |  Owner   |      Created at      |      Updated at
-------------+-------+-------------------+----------+----------+----------------------+-----------------------
  demostore  | Kafka | us-east-1         | {}       | sysadmin | 2022-08-22T17:01:05Z | 2022-08-22T17:01:05Z
  Demostore2 | Kafka | us-east-1         | {}       | sysadmin | 2022-08-22T18:25:25Z | 2022-08-22T18:25:25Z

demodb.public/demostore# USE STORE "Demostore2";
demodb.public/demostore2#

Last updated