Creating a namespace
A namespace defines a group of tables, within which all of the table names must be
uniquely identified. Namespaces permit you to do table privilege management as a group
operation. You can grant authorization permissions to a namespace to determine who can
access both the namespace and the tables within it. Namespaces permit tables with the
same name to exist in your database store. To access such tables, you can use a fully
qualified table name. A fully qualified table name is a table name preceded by its
namespaces, followed with a colon (:), such as ns1:table1
.
All tables are part of some namespace. There is a default Oracle NoSQL
Database namespace, called sysdefault
. All tables are assigned to the
default sysdefault
namespace, until or unless you create other
namespaces, and create new tables within them. You can't change an existing table's
namespace. Tables in sysdefault
namespace do not require a fully
qualified name and can work with just the table name.
CREATE NAMESPACE
statement.CREATE NAMESPACE [IF NOT EXISTS] namespace_name
Note:
Namespace names starting withsys
are reserved. You cannot use the prefix
sys
for any namespaces.
ns1
.CREATE NAMESPACE IF NOT EXISTS ns1
Using APIs to create namespaces:
You can create a namespace using SystemRequest
class. The SystemRequest
class is used to perform any
table-independent administrative operation. These operations are asynchronous
and completion needs to be checked.
private static void createNS(NoSQLHandle handle) throws Exception {
String createNSDDL = "CREATE NAMESPACE IF NOT EXISTS ns1";
SystemRequest sysreq = new SystemRequest();
sysreq.setStatement(createNSDDL.toCharArray());
SystemResult sysres = handle.systemRequest​(sysreq);
sysres.waitForCompletion​(handle, 60000,1000);
System.out.println("Namespace " + nsName + " is created");
}
You can create a namespace using SystemRequest
class. The SystemRequest
class is used to perform any
table-independent administrative operation.
def create_ns(handle):
statement = '''CREATE NAMESPACE IF NOT EXISTS ns1'''
sysreq = SystemRequest().set_statement(statement)
sys_result = handle.system_request(sysreq)
sys_result.wait_for_completion(handle, 40000, 3000)
print('Created namespace: ns1')
You can create a namespace using SystemRequest
class. The SystemRequest
class is used to perform any
table-independent administrative operations. These are potentially long-running
operations and completion of the operation needs to be checked.
func createNS(client *nosqldb.Client, err error)(){
stmt := fmt.Sprintf("CREATE NAMESPACE IF NOT EXISTS ns1")
sysReq := &nosqldb.SystemRequest{
Statement: stmt,
}
sysRes, err := client.DoSystemRequest(sysReq)
_, err = sysRes.WaitForCompletion(client, 60*time.Second, time.Second)
if err != nil {
fmt.Printf("Error finishing CREATE NAMESPACE request: %v\n", err)
return
}
fmt.Println("Created Namespace ns1 ")
return
}
You can create namespace using adminDDL
method. The
adminDDL
method is used to perform any table-independent
administrative operation.
The ExecuteAdminSync
method is used to perform any
table-independent administrative operations.
private static async Task createNS(NoSQLClient client){
var sql =
$@"CREATE NAMESPACE IF NOT EXISTS ns1";
var adminResult = await client.ExecuteAdminAsync(sql);
// Wait for the operation completion
await adminResult.WaitForCompletionAsync();
Console.WriteLine(" Created namespace ns1");
}