KDB copy one table's schema (meta) to another table's

Viewed 95

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?

2 Answers

You could use the meta of one table to cast the other table:

t2:flip(exec upper t from meta t1)$string flip t2

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.

Related