Reputation: 23052
I know I can delete tables using
delete some_table_name from `.
But suppose I have a large number of tables, and want to delete all tables that, say, begin with prefix_
and end with _suffix
.
How can I do this?
Upvotes: 0
Views: 368
Reputation: 2268
If you require this functionality often, I suggest that you define a drop
function as follows:
q)drop:![`.;();0b;](),
This function will take one or more table names as symbols and delete them. Combined with a selector function it can be used to delete by pattern
q)drop{x where x like"prefix_*_suffix"}tables[]
You can also define a drop_matching
function
q)drop_matching:drop{a where(a:tables[])like x}@
that will do the job in one swoop:
q)drop_matching"prefix_*_suffix"
Upvotes: 1
Reputation: 1996
You can use functional form of delete
(see here):
/ create some tables
q)`a_one`a_two`b_one`b_two set\:([] x:til 10)
`a_one`a_two`b_one`b_two
q)tables[]
`s#`a_one`a_two`b_one`b_two
/ find table names matching "a_*" and delete them from root namespace
q)![`.;();0b;{x where x like "a_*"} tables[]]
`.
q)tables[]
`s#`b_one`b_two
Upvotes: 1