USE - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

USE

更改对其运行查询的数据库。SHOW USE 指向最近与 USE 命令一起使用的数据库。RESET USE 会重置所使用的数据库。这意味着,如果未在 SQL 中指定数据库,则将在当前数据库中搜索对象。

语法

USE database

示例

假设有两个数据库:devpdb。假设每个数据库的公有架构中有两个表 t

dev=# insert into dev.public.t values (1); INSERT 0 1 dev=# insert into pdb.public.t values (2); INSERT 0 1 -- USEd database is not set. dev=# show use; Use Database -------------- (1 row) dev=> show search_path; search_path --------------- $user, public (1 row) dev=# select * from t; c --- 1 (1 row) -- Set the USEd database to query the tables in it. dev=# use pdb; USE dev=# select * from t; id ---- 2 (1 row) dev=# select * from public.t; id ---- 2 (1 row) -- Reset the USEd database to again refer to objects in the connected database. dev=# RESET USE; RESET dev=# select * from t; c --- 1 (1 row)