I have a table with one column of strings, I want to create a new column with type string, and ` in front of each string item. How do I do that? example:
Old:
a
b
c
New:
"\`a"
"\`b"
"\`c"
I have a table with one column of strings, I want to create a new column with type string, and ` in front of each string item. How do I do that? example:
Old:
a
b
c
New:
"\`a"
"\`b"
"\`c"
Another solution (faster in this scenario):
q)update b:flip ("`";a) from tab
a b
------
a "`a"
b "`b"
c "`c"
Take the following table as an example:
q)show tab:([]a:("a";"b";"c"))
a
-
a
b
c
To get a new column with the backtick in front you need to append "`"
to each line:
q)update b:("`",'a) from tab
a b
------
a "`a"
b "`b"
c "`c"
If the column consists of symbols then it just needs to be converted to a string first:
q)tab2:([]a:`a`b`c)
q)update b:("`",'string a) from tab2
a b
------
a "`a"
b "`b"
c "`c"
Sometimes people, more familiar with SQL than with q, pose questions in terms of tables, when they need only handle vectors; and create new columns where all that is needed is a variable – or a value to pass as an argument.
q)"`",'tab[`a]
"`a"
"`b"
"`c"
Of course, the a
column of tab
is nothing but the vector "abc"
, so
q)"`",'"abc"
"`a"
"`b"
"`c"
might be all you need.
See: