String vs Symbol

Newbie question. 
Got a table like this t:(aa:();bb:());

Now I need to insert strings like “hello-my-freaking-world” into aa and an integer into b but that does not work as expected. 

Something like t insert ($“hello-my-freaking-world”;1) worked but I don’t understand why symbols are working and strings not. 

I would prefer having proper strings than symbols and looking for an explanation of the behavior. Thanks!

Hi,When defining the table t you need the square brackets at the start of the definition. What you have written is defining a two item list, containing two empty lists. Once you have a table t, inserting strings would work like this:q)t:( aa:();bb:());q)t insert ([] aa:("hello world";"dd"); bb:8 9)0 1q)taa bb----------------"hello world" 8"dd" 9q)meta tc | t f a--| -----aa| Cbb| jRegards,Ryan-- TimeStored.com - KDB+ Training, Consulting, SoftwareOn 15/09/2013 19:31, kdb newb wrote:\> Newbie question.\> Got a table like this t:(aa:();bb:());\>\> Now I need to insert strings like "hello-my-freaking-world" into aa \> and an integer into b but that does not work as expected.\> Something like t insert (`$“hello-my-freaking-world”;1) worked but I > don’t understand why symbols are working and strings not.>> I would prefer having proper strings than symbols and looking for an > explanation of the behavior. Thanks!> – > You received this message because you are subscribed to the Google > Groups “Kdb+ Personal Developers” group.> To unsubscribe from this group and stop receiving emails from it, send > an email to personal-kdbplus+unsubscribe@googlegroups.com.> To post to this group, send email to personal-kdbplus@googlegroups.com.> Visit this group at http://groups.google.com/group/personal-kdbplus.\> For more options, visit https://groups.google.com/groups/opt\_out.

Below gave you a strange result:

q)`t insert (“hello-my-freaking-world”;1)

q)t

aa bb


h  1

e  1

l  1

l  1

o  1

  •  1

m  1

y  1

  •  1

f  1

r  1

e  1

a  1

k  1

i  1

n  1

g  1

  •  1

w  1

o  1

..

The reason for this behavior:

  1. “hello-my-freaking-world” is a list of character (simple list). When inserting a simple list to a corresponding column, each element within a list is added into a new row,

Hence each character has its own row.

  1. since “hello-my-freaking-world” is a list and 1 is an atom, atomic extension happens automatically to make sure both lists have the same length.

Hence 1 is extended into a list containing 1s which match the length of “hello-my-freaking-world” and each element has its own row.

  1. similar to `t insert(“hello-my-freaking-world”;1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1)

A string column is a nested column (a list of a list of character). So to achieve expected result, your first element must be a nested list:

q)`t insert (enlist"hello-my-freaking-world";1)

q)t

aa                        bb


“hello-my-freaking-world” 1

Works now because:

  1. enlist"hello-my-freaking-world" is a nested list containing one element which is a list of character.

So that one element is inserted into one row.

  1. 1 is an atom and extended into a list with length 1 (singleton list).

So that one element is inserted into one row.

  1. similar to  `t insert (enlist"hello-my-freaking-world";enlist 1)

Hope this helps!