For instance, I have:

x: (`a`b!(1;2); (); `a`b!(3;4))

and I want to remove the (). I have tried using ? (match)

x[x ? not ()]

but that just gives ().

What is the correct expression?

Background

I often use peach to execute a series of queries, and often some will return missing data in the form of (). Hence I want to remove the () and get back to a nice table.

有帮助吗?

解决方案 2

You can use except as well:

q)x except 1#()
a b
---
1 2
3 4

其他提示

Well, if you are returning tables already (rather than dictionaries), you could always just raze and that would be enough to get rid of the empty list. Technically, it is appended, but if you append an empty list on a list, you get the original list. Recall that a table is simply a list of dictionaries, so this remains the case here as well.

//I'm enlisting your dictionaries,
//so that they become tables and then raze
q)raze @[x; 0 2; enlist]   
a b
---
1 2
3 4

Snippets such as raze f each x or raze f peach x are very common, and I suspect this is the idiom that would be best for your use case.

() is an empty list. So it has count of zero. Therefore we can use:

q)x where not 0 = count each x
a b
---
1 2
3 4

A slight more generic way to get rid of unwanted elements :

q)x where not x~\:()
a b
---
1 2
3 4

q)x where not x~\:`a`b!(1;2)
()
`a`b!3 4
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top