Updated on 2025-10-23 GMT+08:00

USE

Description

USE specifies the current schema so that the database uses the specified schema as the default (current) schema.

Precautions

To use USE to specify a schema, you must have the USAGE permission on the schema. You can run the SHOW databases; command to view the schemas on which you have the USAGE permission. If you do not have the USAGE permission on a schema and perform operations on the schema, the current schema is set to null and no error message is displayed. You can call the database function to check whether the specified schema takes effect.

m_db=> USE test;
SET
m_db=> SELECT database();
ERROR:  function returned NULL
CONTEXT:  referenced column: database

Syntax

USE schema_name

Parameters

schema_name

Specifies the name of the schema to be specified.

Value range: an existing schema name.

Examples

m_db=# SELECT database();
 database 
----------
 public
(1 row)

m_db=# SHOW DATABASES;
      Database      
--------------------
 information_schema
 blockchain
 db4ai
 dbe_perf
 dbe_pldebugger
 dbe_pldeveloper
 dbe_sql_util
 m_schema
 pg_catalog
 pg_toast
 pkg_service
 public
 snapshot
 sqladvisor
 sys
(16 rows)

m_db=# USE m_schema;
SET
m_db=# SELECT database();
 database 
----------
 m_schema
(1 row)