You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

KDB/Q分区表筛选date列及所有_test后缀列的方法问询

Solution for Selecting Date and All "_test" Suffix Columns in kdb+

Got it, let's fix this for you. The issue with your original delete all except approach is that kdb+ doesn't support wildcard patterns like *_test directly in the except clause—you need to explicitly generate the list of columns you want to keep first.

Step-by-Step Solution

First, let's get the list of columns that end with _test using cols (to fetch all column names) and like (to filter by the suffix pattern):

test_cols: cols[t] where cols[t] like "*_test"

For your sample table, this will return ,a_testb_test.

Then, select the date column along with these filtered columns in one query:

select date, test_cols from t where date=2019.01.01

One-Liner Version

If you prefer a more concise approach, combine the two steps into a single line:

select date, (cols[t] where cols[t] like "*_test") from t where date=2019.01.01

Alternative Using Indexing

You can also use kdb+'s indexing operator ! to extract the desired columns directly:

t[`date, (cols[t] where cols[t] like "*_test")] where t.date=2019.01.01

Verification with Your Sample Table

Let's test this with your example table:

t:([]date:3#2019.01.01; a:1 2 3; a_test:2 3 4; b_test:3 4 5; c: 6 7 8);

Running any of the above queries will give you the expected output:

date       a_test b_test
------------------------
2019.01.01 2      3
2019.01.01 3      4
2019.01.01 4      5

This method scales perfectly even if you have 100+ _test columns—no need to manually list each one!

内容的提问来源于stack exchange,提问作者Utsav

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 07:00:07