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
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
If I would like the data to become
`CS:primary 1
`CS.US:primary 2
`CS.US_ABC:primary 3
and the primary is either string or symbol, how could I join?
I am parameterizing the 0 and primary.
Currently, 0 works as follows
update service:`$(((string[service],'(":"))),'( "0")) from tab
but "primary" is not working
update service:`$(((string[service],'(":"))),'( "primary")) from tab
Your query gives you a length error:
This happens because
,'
(concatenate each) expects vectors of equal length on both sides, but gets a table column size (3) vector on the left and a character vector of length 7 on the right. Notice what happens when you pass 3 characters:Each row gets a different suffix. What you want is to use
,\:
(concatenate each-left):Why does it work for "0"? It works because "0" is not a vector but a character scalar
and with a scalar on the right,
,'
works the same as.\:
:Finally, your query will run faster if you first prepend ":" to the suffix and then append the result to each service:
If you want primary to be a parameter rather than a fixed string, the following will work (primary is "no" in this example):
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: