SET DEFAULT

Syntax

SET DEFAULT { DATABASE | ORGANIZATION | ROLE | SCHEMA | STORE } entity_name;

Description

This sets the Database, Organization, Role, Schema, or Store as the user’s default. Changing defaults does not affect the current session’s context, and it must additionally call USE to change the context. Entering a new user session has the same outcome as changing it with USE.

Any entity used to set as default must already exist and be accessible by the user.

Arguments

entity_name

Name of the entity to set as a default. For case-sensitive names, the name must be wrapped in double quotes; otherwise, the lowercase name will be used.

Examples

Set a new default Database

The following changes the user’s current Database to otherdb:

demodb.public/demostore# LIST DATABASES;
   Name   | Default |  Owner   |      Created at      |      Updated at       
----------+---------+----------+----------------------+-----------------------
  demodb  |        | sysadmin | 2023-01-11T19:59:26Z | 2023-01-11T19:59:26Z  
  otherdb |         | sysadmin | 2023-02-14T20:06:55Z | 2023-02-14T20:06:55Z  
demodb.public/demostore# SET DEFAULT DATABASE otherdb;
demodb.public/demostore# USE DATABASE otherdb;
otherdb.public/demostore#

Set a new default Schema

The following changes the user’s current Schema to the demodb.Analytics Schema within the current Database, demodb:

demodb.public/demostore# LIST SCHEMAS;
    Name    | Default |  Owner   |      Created at      |      Updated at       
------------+---------+----------+----------------------+-----------------------
  Analytics |         | sysadmin | 2023-01-11T19:59:26Z | 2023-01-11T19:59:26Z  
  public    |        | sysadmin | 2023-01-11T19:59:26Z | 2023-01-11T19:59:26Z  
demodb.public/demostore# SET DEFAULT SCHEMA "Analytics";
demodb.public/demostore# USE SCHEMA "Analytics";
demodb.Analytics/demostore#

Last updated