Limits of string transformations in q, stars in TOK

137 Views Asked by At

I'm trying to convert int values to minutes, and in some cases it gives me stars * in the result:

string "U"$"99:59" / "99:59"
string "U"$"100:00" / "**:00"

What are the rules for this stars to appear?

Update for seconds:

string "V"$"1000" / "10:00:00"
string "V"$"10000" / "**:00:00"
string "V"$"100000" / "10:00:00"
string "V"$"1000000" / "**:00:00"

Is it possible to configure this rules, say to stop smudging the origin values?

1

There are 1 best solutions below

0
On

I think the stars that appear are just kdb's way of saying that the result couldn't be displayed. The minute and second datatypes have the form hh:mm and hh:mm:ss, respectively. So if kdb reads the hour part as having more than 3 digits (i.e greater than 99), the stars will appear.

If you're casting a string into a minute datatype, then kdb converts the last two chars into minutes, and the rest into hours, eg

"U"$"1234" / 12:34
"U"$"12345" / **:45

Something similar occurs when you convert a string into seconds. If the length of the string is 6 or greater, then the last two chars are converted into seconds. Otherwise, the seconds are set to 00. The rest of the string is then converted into hh:mm as above. To illustrate this, look at:

"V"$"1234" / 12:34:00
"V"$"12345" / **:45:00
"V"$"123456" / 12:34:56
"V"$"1123456" / **:34:56

I should also note that even though stars appear, you can still do things like temporal arithmetic as usual, eg

"U"$"100:00 / **:00
("U"$"100:00")-"U"$"1:00" / 99:00