Apache Impala SQL ReferencePDF version

USE statement

The USE statement switches the current session to a specified database. The current database is where any CREATE TABLE, INSERT, SELECT, or other statements act when you specify a table or other object name, without prefixing it with a database name. The new current database applies for the duration of the session or unti another USE statement is executed.

Syntax:

USE db_name

By default, when you connect to an Impala instance, you begin in a database named default.

Usage notes:

Switching the default database is convenient in the following situations:

  • To avoid qualifying each reference to a table with the database name. For example, SELECT * FROM t1 JOIN t2 rather than SELECT * FROM db.t1 JOIN db.t2.
  • To do a sequence of operations all within the same database, such as creating a table, inserting data, and querying the table.

To start the impala-shell interpreter and automatically issue a USE statement for a particular database, specify the option -d db_name for the impala-shell command. The -d option is useful to run SQL scripts, such as setup or test scripts, against multiple databases without hardcoding a USE statement into the SQL source.

Examples:

See the CREATE DATABASE statement for examples covering CREATE DATABASE, USE, and DROP DATABASE.

Cancellation: Cannot be cancelled.

HDFS permissions: This statement does not touch any HDFS files or directories, therefore no HDFS permissions are required.

We want your opinion

How can we improve this page?

What kind of feedback do you have?