how to update in-memory table dynamically using dolphindb database

213 Views Asked by At

Is there any way to update an in-memory table dynamically using dolphindb? I need more suggestions to write a dynamic update function. Now I can only get the table name returned. I tried several methods to update the data for a specified table but failed.

Script 1:

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);

Error report:

Read only object or object without ownership can't be applied to mutable function update!

Script 2:

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

Error report:

Invalid expression: update t1 set v=999;

What's the correct syntax to update a specified table?

1

There are 1 best solutions below

0
dbaa9948 On

Use DolphinDB's function update! to update the columns in an existing table:

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

Here table is a DolphinDB table. The error occurs because your script defines the table type to be of STRING type. Use objByName to change it:

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

If you want to know more about dynamical expression generation, meta programming will be of help.