选择何时不存在过滤列之一

问题描述

假设不知道是否存在过滤器列的情况。

t:([]a:`s1`s2`s3; c:1 2 3);
select c from t where null t[`a]
select c from t where null t[`b]
'length
(where null t[`a])~where null t[`b]
1b

该列a存在,则select正常。

但是当我对列b使用过滤器(不存在)时,会出现错误

  1. 为什么会这样? -我已经检查了where的两个结果-它们是相同的
  2. 如何解决这种情况?

解决方法

在QSQL中,“ where”需要作用于表长度相同或计数为1的布尔值列表。示例的计数为零

q)t[`b]
`symbol$()
q)count t`b
0

一些例子:

q)select from t where 0b
a c
---
q)select from t where 00b
'length
  [0]  select from t where 00b
       ^
q)select from t where 000b
a c
---
q)select from t where 0000b
'length
  [0]  select from t where 0000b
       ^
q)select from t where 0#0b
'length
  [0]  select from t where 0#0b

更新: 因为您提到了“ where”的结果,所以where是用QSQL格式包装的,而不是独立起作用,然后应用结果,因此您会看到以下差异

q)where 00b
`long$()
q)select from t where 00b
'length
  [0]  select from t where 00b
       ^
q)select from t `long$()
a c
---
,

您可以利用@运算符来捕获错误,例如

q)@[{select c from t where null t[x]};`b;{x}]
"length"
q)@[{select c from t where null t[x]};`a;{x}]
c
-

尽管您不需要像这样引用列,但如果要动态选择列,则可以使用功能选择,因此功能形式的等效查询将是

q)?[`t;enlist(null;`a);0b;(enlist `c)!(enlist `c)]
c
-

这里的语法非常棘手,但是parse关键字对于找出您应该使用的参数非常有用,例如

q)parse"select c from t where null a"
?
`t,(^:;`a)
0b
(,`c)!,`c

向您显示所需的参数。错误陷阱和功能查询的结合应该可以帮助您实现此处的目标。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...