# How to define empty IndexedTables?

**URL:** https://discourse.julialang.org/t/how-to-define-empty-indexedtables/6508
**Category:** Data
**Tags:** question
**Created:** [October 17, 2017, 3:15pm UTC](https://discourse.julialang.org/t/how-to-define-empty-indexedtables/6508 "2017-10-17T15:15:39Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [October 17, 2017, 3:15pm UTC](https://discourse.julialang.org/t/how-to-define-empty-indexedtables/6508/1 "2017-10-17T15:15:39Z")

</div>

I am unable to define empty IndexedTables, e.g.

```julia
using IndexedTables, IndexedTables.Table
t = Table(Columns(a=Int64[],b=String[]),Int64[])
t[1,"a"] = 1
t[1,"b"] = 2
t[1,"c"] = t[1,"a"] + t[1,"b"]
BoundsError: attempt to access 0-element Array{Int64,1} at index [0]

```

Is there any workaround possible ?

EDIT: I did repost this question [on StackOverflow](https://stackoverflow.com/questions/46805549/how-to-define-empty-indexedtables-in-julia)

---

<div class="post-metadata">

### Author: ![sylvaticus](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sylvaticus/32/203883_2.png) [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)
#### Post date: [October 18, 2017, 8:33am UTC](https://discourse.julialang.org/t/how-to-define-empty-indexedtables/6508/2 "2017-10-18T08:33:18Z")

</div>

It seems it has to do with the fact that inserts are not put straightaway on the data, but on a buffer:

```julia
tok = Table(Columns(a=Int64[1,1],b=String["a","b"]),Int64[1,2])
tbad = Table(Columns(a=Int64[],b=String[]),Int64[])
tbad[1,"a"] = 1
tbad[1,"b"] = 2
dump(tok)
IndexedTables.IndexedTable{Int64,Tuple{Int64,String},IndexedTables.Columns{NamedTuples._NT_a_b{Int64,String},NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}},Array{Int64,1}}
  index: IndexedTables.Columns{NamedTuples._NT_a_b{Int64,String},NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}}
    columns: NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}
      a: Array{Int64}((2,)) [1, 1]
      b: Array{String}((2,))
        1: String "a"
        2: String "b"
  data: Array{Int64}((2,)) [1, 2]
  index_buffer: IndexedTables.Columns{NamedTuples._NT_a_b{Int64,String},NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}}
    columns: NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}
      a: Array{Int64}((0,)) Int64[]
      b: Array{String}((0,))
  data_buffer: Array{Int64}((0,)) Int64[]

dump(tbad)
IndexedTables.IndexedTable{Int64,Tuple{Int64,String},IndexedTables.Columns{NamedTuples._NT_a_b{Int64,String},NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}},Array{Int64,1}}
  index: IndexedTables.Columns{NamedTuples._NT_a_b{Int64,String},NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}}
    columns: NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}
      a: Array{Int64}((0,)) Int64[]
      b: Array{String}((0,))
  data: Array{Int64}((0,)) Int64[]
  index_buffer: IndexedTables.Columns{NamedTuples._NT_a_b{Int64,String},NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}}
    columns: NamedTuples._NT_a_b{Array{Int64,1},Array{String,1}}
      a: Array{Int64}((2,)) [1, 1]
      b: Array{String}((2,))
        1: String "a"
        2: String "b"
  data_buffer: Array{Int64}((2,)) [1, 2]

```

ok, it makes sense, after the various assignments I just have to `flush!(t)` to make them in order all in one go… the problem is that with an empty IndexedTable and after I do `tbad[1,"a"] = 1`, `tbad[1,"b"] = 2` `flush!(tbad)` still returns an `BoundsError: attempt to access 0-element Array{Int64,1} at index [0]` error.

EDIT: This issue has a solution (an edit to the `IndexedTables._merge! function`) in the[parallel S.O. question](https://stackoverflow.com/questions/46805549/how-to-define-empty-indexedtables-in-julia).
