Namespace Management
Namespace Resolution
You can grant authorization permissions to a namespace to determine who can access both the namespace and the tables within it.
table_name
that appears in an SQL
statement, the following rules apply:
-
- If the
table_name
contains a namespace name, no resolution is needed, because a qualified table name uniquely identifies a table. - If you don't specify a namespace name explicitly, the
namespace used is the one contained in the
ExecuteOptions
instance that is given as input to theexecuteSync()
,execute()
, orprepare()
methods of TableAPI. - If
ExecuteOptions
doesn't specify a namespace, the default sysdefault namespace is used.
- If the
Using different namespaces in ExecuteOptions
allows executing the same
queries on separate but similar tables.
Manage Namespaces
SHOW NAMESPACES
The SHOW NAMESPACES statement provides the list of namespaces in the system. You can specify AS JSON if you want the output to be in JSON format.
SHOW NAMESPACES
namespaces
sysdefault
SHOW AS JSON NAMESPACES
{"namespaces" : ["sysdefault"]}
DROP NAMESPACE
You can remove a namespace by using the DROP NAMESPACE statement.
IF EXISTS is an optional clause. If you specify this clause, and if a namespace with the same name does not exist, no error is generated. If you don't specify this clause, and if a namespace with the same name does not exist, an error is generated indicating that the namespace does not exist.
CASCADE is an optional clause that enables you to specify whether to drop the tables and their indexes in this namespace. If you specify this clause, and if the namespace contains any tables, then the namespace together with all the tables in this namespace will be deleted. If you don't specify this clause, and if the namespace contains any tables, then an error is generated indicating that the namespace is not empty.
DROP NAMESPACE IF EXISTS ns1 CASCADE
Namespace scoped privileges
You can add one or more namespaces to your store, create tables within them, and grant permission for users to access namespaces and tables. You can grant the following permissions to users.
- CREATE_ANY_NAMESPACE
- DROP_ANY_NAMESPACE
- CREATE_TABLE_IN_NAMESPACE
- DROP_TABLE_IN_NAMESPACE
- EVOLVE_TABLE_IN_NAMESPACE
- CREATE_INDEX_IN_NAMESPACE
- DROP_INDEX_IN_NAMESPACE
CREATE NAMESPACE IF NOT EXISTS ns;
GRANT MODIFY_IN_NAMESPACE ON NAMESPACE ns TO usersRole;
CREATE TABLE ns:t (id INTEGER, name STRING, primary key (id));
INSERT INTO ns:t VALUES (1, 'Smith');
SELECT * FROM ns:t;
REVOKE CREATE_TABLE_IN_NAMESPACE ON NAMESPACE ns FROM usersRole;
DROP NAMESPACE ns CASCADE;
Note:
You can save all of the above commands as a sql script and execute it in a single command. If you want to execute any of the above commands outside of a SQL prompt, remove the semi colon at then end.