1
votes

What would I do if I want to cast all columns to string during project?

T
| project tostring(a), tostring(b), tostring(c), ...

Is the only way to cast each of them separately?

1
you may want to provide additional info about the use case in which you need to cast all columns to string at query time, and if that's the final step of your query, or you're applying additional logic afterwards - Yoni L.

1 Answers

2
votes

I am not aware of any great way to cast multiple columns and I don't think project alone can do this, but you could do something like this to move the values to a single column and then back into their own columns after casting that single column. I feel like a better way might be possible using lists, but I can't see any off the top of my head.

let Example = datatable(AnInteger: int, ATimestamp:datetime, AString:string)
[
1, datetime(1910-06-11), "test",
2, datetime(1910-06-12), "test2"
];
Example
| evaluate narrow()
| extend p = pack(Column, Value)
| summarize bag=make_bag(p) by Row
| project-away Row
| evaluate bag_unpack(bag)
| extend type1=gettype(ATimestamp),
         type2=gettype(AnInteger),
         type3=gettype(AString) // just to show the values really are strings. Delete for your case

enter image description here