Skip to content
Learn › Get data in: open the docs menu

Write or edit a SQL query on a database

When you connect a SQL database, the connector workspace opens a SQL view: click a table, change the query that reads it, check the rows, and click Save as dataset. While saving you choose what each refresh does (see Choose how a database dataset refreshes). The SQL view works on PostgreSQL, MySQL, SQL Server, Oracle Database, Amazon Redshift, Snowflake, Google BigQuery, Databricks, Apache Hadoop and SAP HANA. MongoDB lists collections only, without a SQL view.

Before you start

Connect the database first: see Connect a database or app. If it sits behind a firewall, see Allow Mammoth through your firewall.

How the SQL view is laid out

After you connect a database, Tables on the left lists the tables the connection can read, grouped by schema or dataset where the database has them (use Filter tables to narrow it). The SQL query view on the right shows the open table's rows, with the query that read them above. Click Ask AI to open the connector's chat beside them.

PostgreSQL connector workspace: Tables list on the left, the SELECT query above the grid and the open table's rows

Open a database table

In Tables, click a table. Mammoth puts a SELECT * FROM query for that table above the grid, runs it and shows the rows. To bring in only some columns, tick them in the table's header: the query changes to read only those columns, and you can save without running it again.

Edit or write the SQL query

  1. Click the query line, or Edit SQL beside it, to open the editor.

  2. Change the SQL to filter rows, pick columns or join tables, for example:

    SELECT order_id, customer_id, amount, created_at
    FROM orders
    WHERE created_at >= '2024-01-01'
    

    Use the table and column names from your own database. Mammoth quotes names the way each database expects when it writes the query for you.

  3. Click Run, or press Ctrl+Enter (⌘↵ on a Mac). Click Stop to cancel a long run.

  4. Click Done to close the editor.

The status line shows how many rows came back and how long the query took, for example Ran in 1.2 s. If the query fails, the error appears under the editor. Click Fix with AI to send the query and the error to the chat.

Filter in the query: bringing in only the rows you need makes the dataset faster to refresh and lighter on your database. See Speed up pipelines and connectors.

Write SQL from a plain-language description

On PostgreSQL, MySQL, SQL Server and SAP HANA, the editor has a Describe the data you need... box.

  1. Type what you want, for example "sales by region last quarter".
  2. Click Write SQL. Mammoth writes the query from your tables.
  3. Review it and click Run.

If it can't, it says Couldn't write SQL for that. Try describing it differently. On the other databases, write the SQL yourself or ask the chat.

Troubleshooting queries and previews

SymptomCauseFix
No tables appearThe database user can't see any tablesCheck its permissions in the database, then click Refresh list. If Mammoth can't list them at all, the list says Couldn't list the tables.
No rows came back.The query ran but matched nothingCheck the WHERE clause
Still reading orders stays on screenA large table takes a while to readClick Stop and narrow the query with a WHERE clause
The query fails with an errorA SQL errorRead the error under the editor, or click Fix with AI
Couldn't write SQL for that. Try describing it differently.Mammoth couldn't turn your description into SQLDescribe it differently, or write the SQL yourself
Was this page helpful?

Something wrong? support@mammoth.io