CREATE NAMESPACE, DROP NAMESPACE

v3.2.0

Group tables that belong together under a namespace.

In this article

A namespace groups tables that belong together, such as tables that are joined or read together. It is a label for that grouping and nothing else: it is not a separate storage area, it does not scope transactions, and it does not let two tables share a name.

Syntax

CREATE NAMESPACE <name>
DROP NAMESPACE <name>

Examples

On a new, empty instance:

kdbs> CREATE NAMESPACE shop
CREATED NAMESPACE shop oid=4000

kdbs> SHOW NAMESPACES
oid,name
0,sys
1,public
4000,shop

kdbs> CREATE TABLE shop.items (id int64, sku char(8), name varchar)
CREATED oid=4001

kdbs> DROP NAMESPACE shop
                     ^
ERR byte 15: namespace oid 4000 cannot be dropped: relation 'items' is still in it

A qualifier that does not match where the table lives is refused, and the error says where it is. In the sandbox, which has the namespaces shop and flight:

kdbs> SELECT * FROM flight.items
                    ^
ERR byte 14: no relation 'flight.items'; 'items' is in namespace 'shop'

A qualifier that names no namespace at all is refused as no namespace named '<name>'.

Remarks

  • Table names are unique across the whole instance. At CREATE TABLE ns.t, the qualifier chooses the namespace; everywhere else it is only checked.
  • An unqualified name always means what it meant before namespaces existed.
  • sys (the catalog views) and public (the default for an unqualified CREATE TABLE) are reserved and cannot be created or dropped.
  • A namespace is never created by being mentioned. CREATE TABLE shpo.carts with no shpo namespace is an error, so a typo cannot create a second namespace.
  • DROP NAMESPACE is refused while the namespace holds any table, and the error names one of them. There is no CASCADE.

Limitations

  • Today a namespace changes no result and no cost. The engine records the grouping for future use.
  • public.t is accepted for a table in public, and is checked like any other qualifier.

Sandbox: the browser sandbox has two namespaces, shop and flight, and CREATE NAMESPACE and DROP NAMESPACE are refused there. Tables can still be qualified, as in SELECT * FROM shop.items, and CREATE TABLE shop.<table> puts a new table in shop.