Insert new data into an array without replace the existings


#1

I used the insert into statement to insert data into an array but when insert a new record this replaces the existing one

this is the array definition

and the current values

{i} val1,val2
{0} '2','1'
{1} '1','0'
{2} '2','6'

and when I insert a new record this replace the first one

AQL% insert into z '[("0","0")]';
{i} val1,val2
{0} '0','0'
{1} '1','0'
{2} '2','6'


there are a way to keep both records ?
How to insert new data to the end of an array?


#2

Yes you can insert data into an array at any point. SciDB is built for n-dimensional arrays, and so the “at the end” idea no longer applies. You have to specifically redimension the data to be at specific coordinates:

[apoliakov@localhost ~]$ iquery -aq "create array foo <val:double> [x=0:*,1000000,0]"
Query was executed successfully

[apoliakov@localhost ~]$ iquery -aq "insert(redimension(apply(build(<val:double> [i=0:3,4,0], random()), x, i), foo), foo)"
{x} val
{0} 2.12099e+09
{1} 2.01097e+09
{2} 1.74166e+09
{3} 9.86122e+08

[apoliakov@localhost ~]$ iquery -aq "insert(redimension(apply(build(<val:double> [i=0:9,10,0], random()), x, i+4), foo), foo)"
{x} val
{0} 2.12099e+09
{1} 2.01097e+09
{2} 1.74166e+09
{3} 9.86122e+08
{4} 1.68488e+09
{5} 2.19193e+08
{6} 4.95209e+08
{7} 4.5304e+08
{8} 8.59702e+08
{9} 1.09403e+09
{10} 9.14428e+08
{11} 8.23139e+08
{12} 1.53696e+09
{13} 1.07353e+08

Please take a look at the paper provided here: viewtopic.php?f=18&t=1661
There’s a detailed explanation of how things work and a more detailed example at the end.