Skip to content

Document space formats #314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rtsisyk opened this issue Sep 19, 2017 · 0 comments
Closed

Document space formats #314

rtsisyk opened this issue Sep 19, 2017 · 0 comments
Assignees

Comments

@rtsisyk
Copy link
Contributor

rtsisyk commented Sep 19, 2017

space:format() is Tarantool way to define columns.

SQL:

CREATE TABLE customer (
    customer_id INTEGER PRIMARY KEY,
    fullname VARCHAR NOT NULL,
    address VARCHAR NOT NULL,
     phone VARCHAR NOT NULL,
     vip BOOLEAN NOT NULL
 );
INSERT INTO customer VALUES(1, 'Mail.Ru', '125167, Leningradsky prospekt 39, bld. 79', '+7 (495) 725-63-57', true);
INSERT 0 1

INSERT INTO customer VALUES(1, 123456, NULL, 12, 'string');
ERROR:  invalid input syntax for type boolean: "string"
LINE 1: INSERT INTO customer VALUES(1, 123456, NULL, 12, 'string');

Tarantool:

tarantool> box.schema.space.create('customers')
tarantool> box.space.customers:create_index('primary', {parts = {1, 'integer'}})
tarantool> box.space.customers:format({
    {name = 'customer_id', type = 'unsigned'},
    {name='fullname', type='string'},
    {name='address', type='string'},
    {name='phone', type='string'},
    {name='vip', type='boolean'}
})
tarantool> box.space.customers:insert({1, 'Mail.Ru', '125167, Leningradsky prospekt 39, bld. 79', '+7 (495) 725-63-57', true})
---
- [1, 'Mail.Ru', '125167, Leningradsky prospekt 39, bld. 79', '+7 (495) 725-63-57',
  true]
...

tarantool> box.space.customers:insert({1, 123456, nil, 12.11, 'string'})
---
- error: 'Tuple field 2 type does not match one required by operation: expected string'
...
  1. Tarantool columns are NOT NULL by default. A new nullable=true option is coming soon, see NULL support in indexes tarantool#1557
  2. Tarantool allows to store arbitrary values after the last defined field. Use 'field_count' option to limit the number of columns to exact value.
  3. Tarantool doesn't support DEFAULT clause because there is no way to implement it in our data model.
  4. A new collation='X' option is coming soon, see Locale-aware indexes tarantool#2650
  5. tuple.fieldname syntax is coming soon, see Tuple field aliases tarantool#1014
  6. Formats are checked since 1.7.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants