S.V
S.V

Reputation: 2793

How can one drop/delete columns from a KDB table in place?

Following the documentation, I tried to do the following:

t:([]a:1 2 3;b:4 5 6;c:`d`e`f) // some input table
`a`b _ t                       // works: delete NOT in place
(enlist `a) _ t                // works: delete NOT in place
t _:`a`b                 // drop columns in place does not work; how to make it to work?
// 'type
//   [0]  t _:`a`b

Thank you very much for your help!

Upvotes: 4

Views: 1170

Answers (3)

Jonathon McMurray
Jonathon McMurray

Reputation: 2981

Michael & Kyle have covered the q-SQL options; for completeness, here are a couple of other options using _:

Using _ as in your question, you can re-assign this back to t e.g.

t:`a`b _ t

You can also use . amend with an empty list of indexes i.e. "amend entire", which can be done in-place by passing `t or not in-place by passing just t e.g.

q).[t;();`a`b _] / not in-place
c
-
d
e
f
q).[`t;();`a`b _] / in-place
`t
q)t
c
-
d
e
f

Upvotes: 0

Michael K
Michael K

Reputation: 226

You should be able to use

delete a,b from `t

to delete in place (The backtick implies in place).

Alternatively, for more flexibility you could use the functional form;

![`t;();0b;`a`b]

Upvotes: 7

kylebonnes
kylebonnes

Reputation: 936

The simplest way to achieve column deletion in place is using qSQL:

t:([]a:1 2 3;b:4 5 6;c:`d`e`f)

delete a,b from `t -- here, the backtick before t makes the change in place.

q)t
c
-
d
e
f

Upvotes: 3

Related Questions