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

时间:2011-12-08 05:08:30

标签: java mysql voltdb

我想创建一个在运行时决定的动态字段的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查询?

2 个答案:

答案 0 :(得分: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.

答案 1 :(得分:1)

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

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