Defining a keyed table with a symbols list

Hi there, 

I am trying to define a keyed table with a list of symbols.

So I started with automatic type definition. ()

t:([id:int$()] symbols:());`

meta tc | t f a-------| -----id | isymbols|t insert(1;abc)'length [0] t insert (1;abc)

So, removing the key id the insert works and the symbols “S” type is defined as expected.

t:0!t;t insert (1;abc)t:1!t;tid| symbols--| -------1 | a b cmeta tc | t f a-------| -----id | isymbols| S

I tried to define it directly.

t: 1!flip idsymbols!"iS"$\:();meta t;c | t f a-------| -----id | isymbols| st insert (1;abc)'type [0] t insert (1;abc)

Of course “S”$() and “s”$() both correspond to a `symbol$().

I would like defining directly a keyed table with a list of symbols without alter unkeyed/keyed definition in the first insertion.

Is there a way to do that in q ?

Thanks.

Osvaldo

You are getting length error because you are passing 1 value for ‘id’ field and 3 values for ‘symbols’ field.

Just enlist your symbol list and it will work fine.

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}span.s1 {font-variant-ligatures: no-common-ligatures}

q)t:([id:`int$()] symbols:());

1) t insert (1;enlist abc)

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}span.s1 {font-variant-ligatures: no-common-ligatures} p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}span.s1 {font-variant-ligatures: no-common-ligatures}

id| symbols

–| -------

1 | a b c

q) meta t

c      | t f a

-------| -----

id     | i    

p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000; background-color: #ffffff}span.s1 {font-variant-ligatures: no-common-ligatures}

symbols| S 

On Friday, 2 November 2018 12:11:17 UTC, Osvaldo Fuica wrote:

Hi there, 

I am trying to define a keyed table with a list of symbols.

So I started with automatic type definition. ()

t:([id:int$()] symbols:());`

meta tc | t f a-------| -----id | isymbols|t insert(1;abc)'length [0] t insert (1;abc)

So, removing the key id the insert works and the symbols “S” type is defined as expected.

t:0!t;t insert (1;abc)t:1!t;tid| symbols--| -------1 | a b cmeta tc | t f a-------| -----id | isymbols| S

I tried to define it directly.

t: 1!flip idsymbols!"iS"$\:();meta t;c | t f a-------| -----id | isymbols| st insert (1;abc)'type [0] t insert (1;abc)

Of course “S”$() and “s”$() both correspond to a `symbol$().

I would like defining directly a keyed table with a list of symbols without alter unkeyed/keyed definition in the first insertion.

Is there a way to do that in q ?

Thanks.

Osvaldo

Thanks RAHUL it works.

I guess the automatic way is the best way to specify a lists of symbols ?

Le vendredi 2 novembre 2018 14:13:52 UTC+1, RAHUL ASATI a écrit :

You are getting length error because you are passing 1 value for ‘id’ field and 3 values for ‘symbols’ field.

Just enlist your symbol list and it will work fine.

q)t:([id:`int$()] symbols:());

1) t insert (1;enlist abc)

id| symbols

–| -------

1 | a b c

q) meta t

c      | t f a

-------| -----

id     | i    

symbols| S 

On Friday, 2 November 2018 12:11:17 UTC, Osvaldo Fuica wrote:

Hi there, 

I am trying to define a keyed table with a list of symbols.

So I started with automatic type definition. ()

t:([id:int$()] symbols:());`

meta tc | t f a-------| -----id | isymbols|t insert(1;abc)'length [0] t insert (1;abc)

So, removing the key id the insert works and the symbols “S” type is defined as expected.

t:0!t;t insert (1;abc)t:1!t;tid| symbols--| -------1 | a b cmeta tc | t f a-------| -----id | isymbols| S

I tried to define it directly.

t: 1!flip idsymbols!"iS"$\:();meta t;c | t f a-------| -----id | isymbols| st insert (1;abc)'type [0] t insert (1;abc)

Of course “S”$() and “s”$() both correspond to a `symbol$().

I would like defining directly a keyed table with a list of symbols without alter unkeyed/keyed definition in the first insertion.

Is there a way to do that in q ?

Thanks.

Osvaldo

KDB doesn’t allow to define any column as ‘list’ type of a particular datatype during table creation.  Thats why when you use either “S” or “s”, they both gets converted to symbol type and not symbol list.
Only way to do it is to define your column as ‘()’ and then when you insert values it will automatically converts that column to that type.

So ‘automatic way’ that you have mentioned is the only way.

Now it is clear, thank you.

Le vendredi 2 novembre 2018 14:49:06 UTC+1, RAHUL ASATI a écrit :

KDB doesn’t allow to define any column as ‘list’ type of a particular datatype during table creation.  Thats why when you use either “S” or “s”, they both gets converted to symbol type and not symbol list.
Only way to do it is to define your column as ‘()’ and then when you insert values it will automatically converts that column to that type.

So ‘automatic way’ that you have mentioned is the only way.