Prompt-to-SQL with OpenAI

Natural language queries

With Space and Time's OpenAI-enabled chatbot, you don't have to know any SQL to interact with the database. You can generate SQL commands from simple natural-language inputs.

The chatbot can be found in the Space and Time Studio. Let's take a look at some example generations:

📘

The chatbot is enabled by OpenAI, and may not return the exact same SQL statement for a given natural language input.

Example queries

Let's write a simple query that will return the top 10 addresses on Ethereum that executed the most transactions

show me the top users on Ethereum by number of transactions limit 10

After executing this prompt, this SQL statement will be generated.

SELECT
  ETHEREUM.TRANSACTIONS.FROM_ADDRESS,
  COUNT(ETHEREUM.TRANSACTIONS.TRANSACTION_HASH) AS TRANSACTION_COUNT
FROM
  ETHEREUM.TRANSACTIONS
GROUP BY
  ETHEREUM.TRANSACTIONS.FROM_ADDRESS
ORDER BY
  CAST(TRANSACTION_COUNT AS DECIMAL(38)) DESC
LIMIT
  10;

Let's try another on Ethereum weekly forecast of active users. We can put input the following into the chatbot:

give me a forecast of active users over time by week 

And this SQL statement will be generated:

SELECT
  DATE_TRUNC ('week', CAST(TIME_STAMP AS DATE)) AS week,
  COUNT(DISTINCT WALLET_ADDRESS) AS active_users
FROM
  ETHEREUM.NATIVE_WALLET
GROUP BY
  DATE_TRUNC ('week', CAST(TIME_STAMP AS DATE))
ORDER BY
  week ASC;

Finally, let's add more logic and ask more challenging questions to get wallet information on Ethereum based on a specific logic. We can put input the following into the chatbot:

show me all the ethereum wallets with a balance > 5 and at least 1 transaction associated

And this SQL statement will be generated:

SELECT 
	ETH.WALLET_ADDRESS,
  CAST(ETH.BALANCE AS DECIMAL(30))
FROM 
	ETHEREUM.NATIVE_WALLET ETH 
INNER JOIN
	ETHEREUM.TRANSACTION TX ON T.TRANSACTION_HASH = T.TRANSACTION_HASH 
WHERE 
	CAST(BALANCE AS DECIMAL(30))>5
GROUP BY 
  ETH.WALLET_ADDRESS