box: support default field values in the space format
Now a field can be assigned a default value in the space format. When a new tuple is inserted into a space, and some of the fields contain null values, those fields will be filled with their respective default values. Closes #8157 @TarantoolBot document Title: Document default field values Product: Tarantool Since: 3.0 Root document: https://www.tarantool.io/en/doc/latest/reference/reference_lua/box_space/format/ The format clause contains, for each field, a definition within braces: `{name='...',type='...'[,is_nullable=...][,default=...]}`, where: * the optional `default` value contains a default value for the field. Its type must be compatible with the field type. If default value is set, it is applied regardless of whether `is_nullable` is true or false. Example: ```lua tarantool> box.space.tester:format{ > {name = 'id', type = 'unsigned'}, > {name = 'name', type = 'string', default = 'Noname'}, > {name = 'pass', type = 'string'}, > {name = 'shell', type = 'string', default = '/bin/sh'}} --- ... tarantool> box.space.tester:insert{1000, nil, 'qwerty'} --- - [1000, 'Noname', 'qwerty', '/bin/sh'] ... ```
Showing
- changelogs/unreleased/gh-8157-default-field-value.md 3 additions, 0 deletionschangelogs/unreleased/gh-8157-default-field-value.md
- src/box/errcode.h 1 addition, 1 deletionsrc/box/errcode.h
- src/box/field_def.c 42 additions, 0 deletionssrc/box/field_def.c
- src/box/field_def.h 4 additions, 0 deletionssrc/box/field_def.h
- src/box/request.c 19 additions, 17 deletionssrc/box/request.c
- src/box/request.h 15 additions, 7 deletionssrc/box/request.h
- src/box/space.c 59 additions, 5 deletionssrc/box/space.c
- src/box/sql.c 2 additions, 0 deletionssrc/box/sql.c
- src/box/tuple_format.c 93 additions, 2 deletionssrc/box/tuple_format.c
- src/box/tuple_format.h 38 additions, 1 deletionsrc/box/tuple_format.h
- test/box/error.result 1 addition, 0 deletionstest/box/error.result
- test/engine-luatest/gh_8157_default_field_value_test.lua 283 additions, 0 deletionstest/engine-luatest/gh_8157_default_field_value_test.lua
Loading
Please register or sign in to comment