Generator Mode

Generator Mode

Generator mode

Click the Settings button below the question input to get to the generator mode. The generator mode is what you want AI to do for you. By default it will generate SQL/NoSQL queries but you can also set it to explain SQL, format SQL or optimize SQL.

Generate query

This is the default generator mode. It will generate a SQL (or NoSQL) query based on the question that you ask (it usually comes with a explanation of what the query does). You can ask it questions like:

  • find user with email johndoe@example.org
  • find all customers who have rented a movie in the last 12 months
  • find all products added in the current month who has at least 1 purchase and the customer information

You don't have to type in English, you can type in any language that you want. The above question in Spanish would be:

Explain SQL

This will explain the SQL query that you have entered (it will explain what each part of the query does). You can ask it questions like:

SELECT
  SUBSTRING(
    email
    FROM
      1 FOR POSITION('.' IN email) -1
  ) AS first_name
FROM
  customer;

And as you can see the answer both explains what the SQL query does and even how to improve it (opens in a new tab).

Format SQL

This will format the SQL query that you have entered (it will make it more readable). You can ask it questions like:

SELECT c.customer_id, c.first_name, c.last_name FROM customer c INNER JOIN rental r ON c.customer_id = r.customer_id WHERE r.rental_date < (CURRENT_DATE - INTERVAL '12 months') AND ( r.return_date IS NULL OR r.return_date > (CURRENT_DATE - INTERVAL '12 months') ) AND c.customer_id NOT IN ( SELECT customer_id FROM rental WHERE rental_date >= (CURRENT_DATE - INTERVAL '12 months') ) GROUP BY c.customer_id;

The answer is a well-formatted SQL query (opens in a new tab) that is easy to read:

select
  supplier_name,
  city
from
  (
    select
      *
    from
      suppliers
      join addresses on suppliers.address_id = addresses.id
  ) as suppliers
where
  supplier_id > 500
order by
  supplier_name asc,
  city desc;
 
aSELECT c.customer_id,
c.first_name,
c.last_name
FROM
  customer c
  INNER JOIN rental r ON c.customer_id = r.customer_id
WHERE
  r.rental_date < (CURRENT_DATE - INTERVAL '12 months')
  AND (
    r.return_date IS NULL
    OR r.return_date > (CURRENT_DATE - INTERVAL '12 months')
  )
  AND c.customer_id NOT IN (
    SELECT
      customer_id
    FROM
      rental
    WHERE
      rental_date >= (CURRENT_DATE - INTERVAL '12 months')
  )
GROUP BY
  c.customer_id;

Optimize SQL

This will optimize the SQL query that you have entered (it will try to make it more efficient). If we use the same SQL query as above in the Format SQL example we the following exhaustive answers answer 1 (opens in a new tab) and answer 2 (opens in a new tab).

Tip: If unhappy with the results, try running the same query again.