Set string data type

160 views
Skip to first unread message

Hemant Verma

unread,
Oct 31, 2015, 7:48:49 AM10/31/15
to personal...@googlegroups.com
Hi,

I need to set the data type for columns c3,c4 as "C" without inserting single record in table

suppose, tab is table having c3,c4 is list column
tab:([] c1:`int$(); c2:`boolean$(); c3:(); c4:())
q)meta tab    
c | t f a     
--| -----
c1| i    
c2| b   
c3|     
c4|        

I want to set c3 and c4 as "C" (string data type) with inserting a record
q)meta tab    
c | t f a    
--| -----
c1| i   
c2| b   
c3| C   
c4| C            

Please let me know how can I do this.

Thanks,
Hemant

Hemant Verma

unread,
Oct 31, 2015, 7:50:28 AM10/31/15
to personal...@googlegroups.com
Correction: I need to do without inserting the record.

Jack Andrews

unread,
Oct 31, 2015, 8:54:44 AM10/31/15
to Kdb+ Personal Developers
This came up before and I think the answer was "can't be done".

There is no type for "list of strings" in q, well, there is, but it's 0h, the same as for any list of lists.
kdb+ can only decide the type of generic columns after the first row is inserted.
but even then, there are no checks that the future inserts match the type of the first row:

q)p:([]a:`long$();c:())
q)`p insert (3;1 2)
,0
q)p
a c
-----
3 1 2
q)`p insert (3;"df")
,1
q)p
a c
-----
3 1 2
3 d f
q)`p insert (3;"dfd")
,2
q)p
a c
-------
3 1 2
3 "df"
3 "dfd"
q)meta p
c| t f a
-| -----
a| j
c| J

ta, jack


--
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-kdbpl...@googlegroups.com.
To post to this group, send email to personal...@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/d/optout.

RAHUL ASATI

unread,
Oct 31, 2015, 4:32:59 PM10/31/15
to Kdb+ Personal Developers
Hi,
No you  can not do that. In case of table column types,the capital letters that are given by meta  like "I", "C" ,"J"  etc are not an actual datatype in kdb. They are just used to represent general list with some additional characteristics in case of tables. So if you want to convert empty list () to "C" (or "I"), basically its the conversion from general list to general list. Its only after first record you can get "C" but again kdb doesn't stops you from inserting any other type of data later in that column as also mentioned in other post. 

Example:

q) t:([]a:(1 2;3 4))
q) meta t
q) c | t f a
    a | J

q) type t`a
 q) 0h
Reply all
Reply to author
Forward
0 new messages