🔍

Delete

Currently, there is no special verb DELETE for deleting information in tables. This can be done in different ways. Let's consider examples.

Delete columns in an in-memory table:

o)t: +`a`b`c`d!(!10; 10+!10; 100+!10; 1000+!10);
o)nt: `c _ t
a b  d
---------
0 10 1000
1 11 1001
2 12 1002
3 13 1003
4 14 1004
5 15 1005
6 16 1006
7 17 1007
8 18 1008
9 19 1009
o)nt: +`a`d!t`a`d
a d
------
0 1000
1 1001
2 1002
3 1003
4 1004
5 1005
6 1006
7 1007
8 1008
9 1009
o)

o)load "sql";
o)nt:select a, c from t
a c
-----
0 100
1 101
2 102
3 103
4 104
5 105
6 106
7 107
8 108
9 109
o)

Delete columns in an on-disk table:

o)t: +`a`b`c`d!(!10; 10+!10; 100+!10; 1000+!10); f:`:/tmp/t/; f set t;
o)`:/tmp/t/.d set `a`d
`:/tmp/t/.d
o)load  `:/tmp/t/;
o)t
a d
------
0 1000
1 1001
2 1002
3 1003
4 1004
5 1005
6 1006
7 1007
8 1008
9 1009

We draw your attention to the fact that deletion from the table is a relatively slow operation. It should not happen often, as it is the same select from the whole table.

Delete rows in an in-memory table:

o)t: +`a`b!(!10; 10+!10);
o)nt: 4 # t
a b
----
0 10
1 11
2 12
3 13
o)nt: -4 # t
a b
----
6 16
7 17
8 18
9 19
o)nt: (t[`a] in 3 5) # t
a b
----
3 13
5 15
o)nt: (~t[`a] in 3 5) # t
a b
----
0 10
1 11
2 12
4 14
6 16
7 17
8 18
9 19
o)nt: 5 _ t
a b
----
5 15
6 16
7 17
8 18
9 19
o)nt: -5 _ t
a b
----
0 10
1 11
2 12
3 13
4 14

o)t: +`a`b!(!10; 10+!10);
o)remove_by_i: {i:(#y)#1b; i[x]:0b; i#y};
o)nt: remove_by_i[1 3 5 7; t]
a b
----
0 10
2 12
4 14
6 16
8 18
9 19

o)load "sql";
o)t: +`a`b!(!10; 10+!10);
o)nt: select [4] from t
a b
----
0 10
1 11
2 12
3 13
o)nt: select [-4] from t
a b
----
6 16
7 17
8 18
9 19
o)nt: select [4 3] from t
a b
4 14
5 15
6 16
o)select from t where a>4, a<7
a b
----
5 15
6 16
o)// using virtual column i
o)select from t where i>4, i<7
a b
----
5 15
6 16
o)

Delete rows in an on-disk table:

Don't do that. Seriously. Just select records you want to retain and replace original table.

<<< prev UPDATE
next >>> SQL-like syntax