CREATE NAMESPACE, DROP NAMESPACE
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 ops
CREATED NAMESPACE ops oid=4000
kdbs> SHOW NAMESPACES
sys public ops
kdbs> CREATE TABLE ops.gates (id int64, flight_id int64)
CREATED oid=4001
kdbs> DROP NAMESPACE ops
^
ERR byte 15: namespace oid 4000 cannot be dropped: relation 'gates' is still in it
A qualifier that does not match where the table lives is refused, and the error says where it is. Here a namespace cargo also exists:
kdbs> SELECT * FROM cargo.gates
^
ERR byte 14: no relation 'cargo.gates'; 'gates' is in namespace 'ops'
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) andpublic(the default for an unqualifiedCREATE TABLE) are reserved and cannot be created or dropped.- A namespace is never created by being mentioned.
CREATE TABLE opz.gateswith noopznamespace is an error, so a typo cannot create a second namespace. DROP NAMESPACEis refused while the namespace holds any table, and the error names one of them. There is noCASCADE.
Limitations
- Today a namespace changes no result and no cost. The engine records the grouping for future use.
public.tis not accepted as a spelling oft.
Sandbox: namespaces are disabled in the browser sandbox.