Re: Assigning values to `char$() type variable in Insert command

Hello Vajindar,

So when you are casting you are expecting this table to insert atoms and not lists. To avoid this you can set it as an empty table and then insert upon this like so; this will cast the column to the datatype inserted:

q)dt:([dn:()] dname:(); location:())

q)

q)`dt insert (1 2 3i;“CDE”;“GHJ”)

0 1 2

q)dt

dn| dname location

–| --------------

1 | C     G       

2 | D     H       

3 | E     J       

q)meta dt

c       | t f a

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

dn      | i    

dname   | c    

location| c   

May I suggest you use symbols instead of characters as it is much easier to add multiple elements to your table, these can then be casted to strings separately if needed I believe. 

Hi,

q)deptTable:([deptno:`long$()] dname:();loction:())

q)deptTable,:deptnodname`loction!(10; “Accounting”; “New York”)

q)deptTable

deptno| dname        loction   

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

10    | “Accounting” “New York”

Use symbols if there’s values that repeat often (think of currency pairs).

Use strings otherwise.

`char$() means it’s a column of single chars: “A”

nested types you declare with ().

A table column is a list, and in a string column every item is also list, so a list-of-lists, hence ‘nested’.

meta helps a bit, it shows nested columns as uppercase:

q)meta deptTable

c      | t f a

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

deptno | j    

dname  | C    

loction| C