SleepingInsomniac
SleepingInsomniac

Reputation: 47

Delete column based on type in KDB+

I have a table with a bunch of columns of various types. I need to delete all columns of a particular type, but I can't figure out how to do this.

I would like something like this:

delete from quotes where type = 11

But this doesn't work. Is there a way to do this? I was also able to list the relevant columns with the command

select c from meta quotes where type="s"

But this gives me a one column table with the column headings and I don't know where to go from there.

Upvotes: 1

Views: 303

Answers (1)

terrylynch
terrylynch

Reputation: 13572

Could use a functional delete (!), or a take (#) or a drop (_)

q)t:([] col1:`a`b`c;col2:1 2 3;col3:`x`y`z;col4:"foo")

q)![t;();0b;exec c from meta[t] where t="s"]
col2 col4
---------
1    f
2    o
3    o

q)(exec c from meta[t] where t<>"s")#t
col2 col4
---------
1    f
2    o
3    o

q)(exec c from meta[t] where t="s") _ t
col2 col4
---------
1    f
2    o
3    o

Upvotes: 2

Related Questions