Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
119 views
in Technique[技术] by (71.8m points)

请问怎么动态更新内存表

请问一下目前DolphinDB database是否有办法动态操作一张内存表,即把update语句写成动态的。目前我们前端会将数据表名传回来,但是我试了几种办法都不能直接更新指定的内存表,有什么解决方法么?
比如下面代码:

table1=table(1..6 as id,2..7 as v, 3..8 as v1, 4..9 as v2, 5..10 as v3 );
share table1 as t1;
tableName ="t1";
update!(tableName, `v, 666);

执行后报错:
Read only object or object without ownership can't be applied to mutable function update!
再比如下面代码:

updateSql?=?"update?t1?set?v?=?999;";
parseExpr(updateSql).eval;

执行后报错:
Invalid expression: update t1 set v=999;


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

DolphinDB中有个update!可以就地更新表中的列,它的语法是

update!(table, colNames, newValues, [filter])

其中的参数table是DolphinDB中Table类型的表。上面代码的问题是给table赋值了一个字符串,可以用objByName转换一下,代码如下:

update!(objByName(tableName), `v, 666);

更多有关动态更新内存表的内容请参阅元编程教程 2.1节。


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...