1

I want to create a sql query of dynamic fields that are decided at runtime, such as:

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

Because there is a restriction that you must declare an instance variable SQLStmt:

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

Since all fields are hard-coded or else VoltDB will not compile, I cannot set the fields I want to read.

So, How do you create a sql query of dynamic fields using a final string in VoltDB?

Some Noob Student
  • 14,186
  • 13
  • 65
  • 103

2 Answers2

1

It turns out that VoltDB does not support dynamic fields. Here's an exact response from the developers of 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.
Some Noob Student
  • 14,186
  • 13
  • 65
  • 103
1

As the question is written, there is no way to create a sql query of dynamic fields using a final string in VoltDB, because there is no way to modify a final string at runtime. The reason the SQLStmt class is final is because the statements are compiled when the volt compiler creates the catalog. You can use parameters or "bind variables", but you cannot make the columns you refer to in a query dynamic.

You can, however, use the @AdHoc system procedure to run a dynamically-generated SQL statement. Here is an example.

BenjaminBallard
  • 1,482
  • 12
  • 11