box.schema.space.create() / schema_object:create_space() | Tarantool
Reference Built-in modules reference Module box Submodule box.schema box.schema.space.create() / schema_object:create_space()

box.schema.space.create() / schema_object:create_space()

box.schema.space.create(space-name[, {options}])
box.schema.create_space(space-name[, {options}])

Create a space.

Parameters:
  • space-name (string) – name of space, which should conform to the rules for object names
  • options (table) – see “Options for box.schema.space.create” chart, below
Return:

space object

Rtype:

userdata

You can use either syntax. For example, s = box.schema.space.create('tester') has the same effect as s = box.schema.create_space('tester').

Options for box.schema.space.create

Name Effect Type Default
engine ‘memtx’ or ‘vinyl’ string ‘memtx’
field_count fixed count of fields: for example if field_count=5, it is illegal to insert a tuple with fewer than or more than 5 fields number 0 i.e. not fixed
format field names and types: See the illustrations of format clauses in the space_object:format() description and in the box.space._space example. Optional and usually not specified. table (blank)
id unique identifier: users can refer to spaces with the id instead of the name number last space’s id, +1
if_not_exists create space only if a space with the same name does not exist already, otherwise do nothing but do not cause an error boolean false
is_local space contents are replication-local: changes are stored in the write-ahead log of the local node but there is no replication. boolean false
temporary space contents are temporary: changes are not stored in the write-ahead log and there is no replication. Note re storage engine: vinyl does not support temporary spaces. boolean false
user name of the user who is considered to be the space’s owner for authorization purposes string current user’s name

Saying box.cfg{read_only=true...} during configuration affects spaces differently depending on the options that were used during box.schema.space.create, as summarized by this chart:

Option Can be created? Can be written to? Is replicated? Is persistent?
(default) no no yes yes
temporary no yes no no
is_local no yes no yes

There are three syntax variations for object references targeting space objects, for example box.schema.space.drop(space-id) will drop a space. However, the common approach is to use functions attached to the space objects, for example space_object:drop().

Example:

tarantool> s = box.schema.space.create('space55')
---
...
tarantool> s = box.schema.space.create('space55', {
         >   id = 555,
         >   temporary = false
         > })
---
- error: Space 'space55' already exists
...
tarantool> s = box.schema.space.create('space55', {
         >   if_not_exists = true
         > })
---
...

After a space is created, usually the next step is to create an index for it, and then it is available for insert, select, and all the other box.space functions.

Found what you were looking for?
Feedback