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 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) 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 shpo.cartswith noshponamespace 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 accepted for a table inpublic, and is checked like any other qualifier.
Sandbox: the browser sandbox has two namespaces,
shopandflight, andCREATE NAMESPACEandDROP NAMESPACEare refused there. Tables can still be qualified, as inSELECT * FROM shop.items, andCREATE TABLE shop.<table>puts a new table inshop.