本文介绍了如何在kdb中的表中联接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在kdb中加入字符串,但是效果不佳.这是数据:

I would like to join string in kdb but didn't work well. This is the data:

tab:([]service:`CS`CS.US`CS.US_ABC;y:1 2 3)


`CS 1
`CS.US  2
`CS.US_ABC  3

我想根据给定的参数添加:0和:primary. 0正在工作

I would like to add :0 and :primary depending on the given parameter. 0 is working now

update service:`$(((string[service],'(":"))),'("C"$string 0)) from tab

如果我希望数据成为

`CS:primary 1
`CS.US:primary  2
`CS.US_ABC:primary  3

主要是字符串或符号,我如何加入?

and the primary is either string or symbol, how could I join?

我正在参数化0和primary.

I am parameterizing the 0 and primary.

当前,0的工作方式如下

Currently, 0 works as follows

update service:`$(((string[service],'(":"))),'( "0")) from tab

但是主要"功能不起作用

but "primary" is not working

update service:`$(((string[service],'(":"))),'( "primary")) from tab

推荐答案

如果希望将primary作为参数而不是固定字符串,则可以使用以下命令(在此示例中primary为"no"):

If you want primary to be a parameter rather than a fixed string, the following will work (primary is "no" in this example):

q)update {`$string[y],\:":",x}[primary;]service from tab
service      y
--------------
CS:no        1
CS.US:no     2
CS.US_ABC:no 3

如果primary是固定字符串,则可以将其放置在lambda中,以代替"x",并将"y"替换为"x",从而产生以下结果:

If primary is a fixed string then you can place it inside the lambda in lieu of "x" and replace "y" with "x", yielding the following:

q)update {`$string[x],\:":","primary"}service from tab
service           y
-------------------
CS:primary        1
CS.US:primary     2
CS.US_ABC:primary 3

这篇关于如何在kdb中的表中联接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 10:55