Natural Language Queries

Space and Time DB accepts natural language in addition to standard SQL

Like any data warehouse, Space and Time Database accepts standard SQL to efficiently query data. While SQL is fairly easy for most data analysts, it still presents a barrier of use to business professionals and non-technical users.

To expand the number of users that can directly participate in directly asking analytic queries, Space and Time allows users to type in natural language queries, which AI automatically translates into SQL and executes on the user's behalf. This opens the door for non-technical users to ask their own questions directly, using their own language of choice, rather than waiting in a work queue for the next data analyst.


Try out AI-SQL on Space and Time

Running natural language SQL wouldn't be interesting if it were difficult - fortunately it's extremely easy!

First, login to Space and Time Studio

To login to Space and Time Studio dapp:

Navigate to the Space and Time Studio dapp and click on "Sign in" in the upper-right most corner.

Enter your Username and Password, and click "Login"

  OR

Click the "Connect a wallet" button at the bottom, and use your wallet to sign into your Space and Time account.

Once authenticated, you should see the "Sign in" button replaced by a "My account" button in the upper right, where you can manage your account and subscription settings.

🔥 New User? Click here to create an account! 🔥



Click on the "Queries" tab so that the "Query Editor" pops up. You might notice that the empty editor invites you to:

Write a SQL query or natural language query prompt...

Let's try a simple prompt using preloaded Ethereum data. Enter in the query editor:

show me the count of Ethereum wallets with a balance greater than a billion for last week

...and hit the "Run Query".

🚧

There is a toggle in the upper-right of the query editor - make sure this is "AI Enabled" (default) to take advantage of this capability!

The LLM is sent context by the Space and Time Database on the data model, table/column meaning, business context, etc. All of this context ensures the SQL written by the AI will be accurate.

The sample prompt above generated the SQL, and result:

You'll see that your original prompt was left at the top of the SQL, commented out (in green). This allows you to see your original request, and compare it to the SQL below if you have questions.

Other Prompts to Try:

Here are a handful of natural language prompts to try with Space and Time Database SQL-AI capability:

Show me the count of 721 NFT transfers over the last rolling 27 days for the contract: 0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d


Show me all wallets on Ethereum that also exist on Polygon, over the last two calendar months for both chains


Show me the TPS by hour on Aptos for the last 7 days


Show me the aggregate balance in the uniswap v3 smart contract 0xae2a25cbdb19d0dc0dddd1d2f6b08a6e48c4a9a9 over the last 8 weeks


Show me the max number of transactions per block over the last week for the ethereum blockchain,added to the max number of transactions per block over the last month for the polygon blockchain. Create a table alias with the first three letters of each schema, and add the table name to each row, under the column name tbl_name. Also add a column that describes your emotional state right now.

Tips and Tricks:

When running queries on Space and Time Database, here are some Tips and Tricks that will help your analysis run fast and efficient:

  • Almost all tables loaded by Space and Time are partitioned by Time_Stamp field, so filtering by any length of time will improve performance.
  • Due to inconsistencies in how outside entities store or represent contract / wallet addresses, SxT stores all contracts in lower case for EVMs (which are case insensitive per standard). When filtering by an address, ensure it is lower cased, or wrap with lower() function.
  • Queries should be automatically routed to the correct engine, but if you want to force a query to a particular engine, you can use: SELECT /*! USE ROWS */ ... to target the low-latency (row-based) transactional engine, or SELECT /*! USE COLS */ ...to target the big-data (columnar) analytic engine.
  • For natural language / AI queries, give detailed instructions and don't be afraid to repeat yourself on longer prompts. If it doesn't give you what you want, try to rephrase your request (like you would with a human).
  • AI will often put a limit 20 statement at the bottom, limiting the number of rows returned. If you're expecting more rows than this limit, simply bump up the limit statement to something higher (like 1000 - will be at the very bottom of the query) and re-run.
  • Remember, you can save your queries in the Space and Time Studio!