如何用unionAll将两个表合成一个表的问题

我现在有两个表,可以用id关联,表t1的x列存的是int类型的值,表t2的x列存的是string类型的值,我现在想用dolphindb中的unionAll函数将两个表合成一个表,我尝试了以下两种写法都不行:

t1=table(1 2 3 as id, 11 12 13 as x)
t2=table(3 4 5 as id, `a`b`c as x)
unionAll(t1,t2);
/*错误:
unionAll(t1, t2) => Failed to append data to column 'x' 
*/
t1=table(1 2 3 as id, 11 12 13 as x)
t2=table(3 4 5 as id, `a`b`c as x)
unionAll(t1,t2,true);
/*错误:
unionAll(t1, t2, 1) => The data type of column [x] of the input table [#1] is inconsistent with that of other input tables.
*/

请问应该怎么办?

请先 登录 后评论

1 个回答

Jax Wu

因为t1和t2的x列中的数据类型不一样,导致不能合并到同一列。
可以将t2的x列列名修改为y,然后再用unionAll进行连接:

t1=table(1 2 3 as id, 11 12 13 as x)
t2=table(3 4 5 as id, `a `b `c as y)
unionAll(t1,t2, true)

返回:
attachments-2021-06-Ryhbzwb360c17bc3cafc9.png

请先 登录 后评论