1

我想创建一个在运行时决定的动态字段的 sql 查询,例如:

SELECT some, random, field FROM table WHERE id = ?

因为存在必须声明实例变量 SQLStmt 的限制:

public final SQLStmt sql = new SQLStmt("SELECT field0, field1 FROM table WHERE id = ?");

由于所有字段都是硬编码的,否则 VoltDB 将无法编译,因此我无法设置要读取的字段。

那么,如何使用 VoltDB 中的最终字符串创建动态字段的 sql 查询?

4

2 回答 2

1

事实证明,VoltDB 不支持动态字段。以下是 VoltDB 开发人员的准确回应:

VoltDB doesn't support the random row query you want here. You have to declare your SQL in advance. We only support parameterization of predicate expressions. If there is limited (say < 50MB) of data associated to id, you can use SELECT * FROM table WHERE id = ?; and filter in your stored procedure logic. Not ideal - but not particularly difficult, either. If ID is the partition attribute for this table, filtering in Java should be fast.

Ryan.
于 2011-12-08T17:22:41.167 回答
1

正如问题所写,没有办法使用 VoltDB 中的最终字符串创建动态字段的 sql 查询,因为无法在运行时修改最终字符串。SQLStmt 类是 final 的原因是因为语句是在 volt 编译器创建目录时编译的。您可以使用参数或“绑定变量”,但不能使查询中引用的列成为动态的。

但是,您可以使用@AdHoc 系统过程来运行动态生成的 SQL 语句。这是一个例子

于 2012-03-15T13:31:07.073 回答