'KDB copy one table's schema (meta) to another table's
I'm trying to map one table's schema to another table,
For instance, I have t1 and t2, which have exact column names and order but different datatype, but I want (meta t2)~meta t1. //1b.
My idea is to copy datatype string of t1 using meta, say it's "SFFFFFJJJ". Then store t2 to .csv and read it with "SFFFFFJJJ". This works but not smart, could anyone come up with better ideas?
Solution 1:[1]
This is based on the same principle as you mention, without the need to save the csv-formatted table:
{(upper (0!meta y)`t;enlist",")0:","0:x}[t1;t2]
This will return the table t1 but with the schema of t2.
Here, ","0:x is Prepare Text which converts the table into a list of strings, with data delimited by commas. The (...;...)0: is Load CSV where the types are being supplied t2's meta table.
Solution 2:[2]
You could use the meta of one table to cast the other table:
t2:flip(exec upper t from meta t1)$string flip t2
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | kylebonnes |
| Solution 2 | Scott |
