Andrey
Andrey

Reputation: 184

How to change format of sql table in Tarantool

I want to add nullable column to sql table, but changing table format leads to an error:

box.execute([[
    CREATE TABLE test(
        "id" INTEGER PRIMARY KEY AUTOINCREMENT,
        "name" TEXT NOT NULL
    )
]])

f = box.space.TEST:format()

table.insert(f, {type='string', name='description', is_nullable=true})

box.space.TEST:format(f)

error: 'Can''t modify space ''TEST'': exact_field_count must be either 0 or >= formatted
    field count'

So is there any way to change format of sql table?

Upvotes: 3

Views: 251

Answers (2)

Peter Gulutzan
Peter Gulutzan

Reputation: 485

An update: In the latest stable Tarantool version (2.7.2) it is now possible to add a column with ALTER, for example box.execute([[ALTER TABLE test ADD COLUMN third INTEGER;]])

Upvotes: 0

akudiyar
akudiyar

Reputation: 370

At the moment (Tarantool 2.4 beta) there is an open issue about that. The source of the problem is that tables created via SQL DDL contain non-null field_count property in metadata, which forbids saving larger tuples into the space.

However, if you specified field_count when creating the space or used SQL DDL for creating it, and decided to add a tuple/column, here is a workaround for setting the field_count value to 0:

tarantool> box.space._space:update(box.space.YOUR_SPACE.id, {{'=',5,0}})

After that, you will be able to change the space format and insert larger tuples. Replace YOUR_SPACE with the actual name of your space. In case of a space created via SQL DDL this name will be the SQL table name in capital letters.

Upvotes: 3

Related Questions