Skip to content

SQL Cookbook

SQL queries are submitted through xtdb.api/q:

  • (xt/q <node> <query> <opts>?) returns the query results as a vector of maps.

    • opts: map of query options

      • :args: vector of query arguments

      • :basis, :tx-timeout, :default-all-valid-time?: see XTQL By default, :default-all-valid-time? is false, unlike the SQL:2011 specification - to maintain SQL spec compatibility, specify :default-all-valid-time? true.

  • (xt/q& <node> <query> <opts>?): returns a CompletableFuture of the query results.

For example:

(xt/q node "SELECT u.first_name, u.last_name FROM users u WHERE xt$id = ?"
      {:args ["James"], :default-all-valid-time? true})

For more details on XTDB’s SQL support, see the SQL reference documentation.