0

VoltDB provides a python client to allow user to interact with database in python. https://github.com/VoltDB/voltdb-client-python

However, I could not figure out how to create a relation through python. The sample scripts only contain "SELECT" and "INSERT" queries.

Anyone have an idea how to do this?

Mark Jin
  • 2,616
  • 3
  • 25
  • 37

1 Answers1

0

Are you asking how to create tables and other objects in your schema through python? It is certainly possible to run DDL statements from the python client, but typically users will load their DDL using SQLCMD.

Here is the VoltDB DDL reference: https://docs.voltdb.com/UsingVoltDB/AppxDDL.php

Here is the DML reference: https://docs.voltdb.com/UsingVoltDB/AppxSQL.php

The Python client library comes with two examples. One is a simple "Hello World" app that calls two procedures which are very simple examples that only do a single select or insert. Perhaps that was the one you were looking at.

The second example is a "voter" client, which goes with the voter app found in the VoltDB kit under ./examples/voter. It also calls procedures, but the procedures in the Voter example are more complex.

If you want to call a SQL statement directly from Python, you do this also by calling a procedure, but in this case it is the built-in @AdHoc system procedure. For example:

client = FastSerializer("localhost", 21211)
sql_proc = VoltProcedure( client, "@AdHoc",[FastSerializer.VOLTTYPE_STRING] )
result_table = sql_proc.call(["SELECT * FROM helloworld"]).tables[0]
for row in result_table.tuples:
    hello = row[0]
    world = row[1]
    dialect = row[2]
    print 'In %s, they say %s %s.' % (dialect, hello, world)

Disclaimer: I work for VoltDB.

elixenide
  • 44,308
  • 16
  • 74
  • 100
BenjaminBallard
  • 1,482
  • 12
  • 11