> ## Documentation Index
> Fetch the complete documentation index at: https://ngquct-docs-fix-500-query-results.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Autocomplete

> Schema-aware SQL autocomplete for keywords, tables, columns, and functions

An alias and a dot give you that table's columns, and that holds for a subquery or a `WITH` table that exists only in the statement you are writing. Everything the popup offers is decided by where the cursor sits.

It opens itself after FROM, JOIN, ON and the other clauses with a short answer, and stays shut where a full list would be noise, such as after a comma in a SELECT list. `Ctrl+Space` overrides both.

<Frame caption="Context-aware autocomplete">
  <img className="block dark:hidden" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/autocomplete.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=9e48fd7408b08d5bd753b648c13fe02c" alt="Autocomplete" width="1560" height="960" data-path="images/autocomplete.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/ngquct-docs-fix-500-query-results/hA72m8tSnRe3b-ew/images/autocomplete-dark.png?fit=max&auto=format&n=hA72m8tSnRe3b-ew&q=85&s=3e090e62ade3af1479494a480cf80ea4" alt="Autocomplete" width="1560" height="960" data-path="images/autocomplete-dark.png" />
</Frame>

| Key              | Action                                             |
| ---------------- | -------------------------------------------------- |
| `Ctrl+Space`     | Open the popup anywhere, even with an empty prefix |
| `Up` `Down`      | Move through suggestions                           |
| `Return` / `Tab` | Accept the selected suggestion                     |
| `Escape`         | Dismiss and keep typing                            |

There is no setting for autocomplete and nothing to turn off. What the popup offers depends entirely on where the cursor sits.

## SQL keywords

```sql theme={null}
SEL|  -- SELECT
FROM users WH|  -- WHERE
```

## Table names

Tables appear after FROM, JOIN, INSERT INTO and similar keywords, and lead the list ahead of keywords there. The clause is read at the cursor, so a second or third JOIN still offers tables.

```sql theme={null}
SELECT * FROM |  -- All tables
SELECT * FROM us|  -- Tables starting with "us": users, user_roles
SELECT * FROM a JOIN b ON a.id = b.id JOIN |  -- All tables, even after an ON condition
```

## Column names

A FROM clause anywhere in the statement, even after the cursor, decides which tables columns come from. With no FROM clause yet every cached table contributes, and ambiguous names are qualified: `users.id`, `orders.id`.

```sql theme={null}
SELECT na|  -- Columns matching "na" from all cached tables
SELECT | FROM users  -- Columns from users
SELECT u.| FROM users u  -- Columns from users via alias
SELECT * FROM users WHERE |  -- Columns from users
```

## Aliases, subqueries and CTEs

An alias followed by `.` gives that table's columns. A derived table or a `WITH` table gives the columns its own SELECT list produces:

```sql theme={null}
SELECT ahs.|  -- country, avg_score
FROM happiness_scores hs
LEFT JOIN (
    SELECT country, AVG(score) AS avg_score
    FROM happiness_scores
    GROUP BY country
) ahs ON hs.country = ahs.country

WITH totals AS (
    SELECT region, SUM(amount) AS total FROM sales GROUP BY region
)
SELECT t.| FROM totals t  -- region, total
```

`AS name`, bare names and qualified `t.col` all resolve. A `SELECT *` subquery and an unaliased `AVG(score)` have no name to offer, so they are skipped.

## Functions and operators

Functions appear in SELECT, WHERE and expression contexts, the connection's own dialect alongside the common SQL ones: `CONVERT_TIMEZONE` on Snowflake, `SAFE_CAST` on BigQuery.

```sql theme={null}
SELECT COUNT(|  -- Columns and *
WHERE date_column > |  -- NOW(), CURRENT_DATE, …
```

Operators the dialect declares appear in WHERE, ON, HAVING and AND, each with what it does and the types it takes. On PostgreSQL that covers JSON, array and range containment, regex, full-text search and the network operators:

```sql theme={null}
WHERE data -|            -- ->  (field as json), ->>  (field as text)
WHERE payload @|         -- @>  contains, @?  JSON path returns any item
WHERE tags &|            -- &&  arrays overlap
WHERE email ~|           -- ~   POSIX regex, ~* case insensitive
```

An operator restricted to `jsonb` is held back on a `json` column rather than offered and rejected by the server.

## Casts and enum values

Typing `::` offers the dialect's type names in the spelling you write, not the internal catalog name. Comparing against a column whose type declares a fixed set of values, a PostgreSQL enum for instance, offers those values quoted:

```sql theme={null}
SELECT id::|             -- integer, bigint, text, timestamptz, jsonb, uuid, …
SELECT payload::js|      -- json, jsonb, jsonpath
WHERE status = |         -- 'pending', 'active', 'archived'
WHERE mood <> 'ha|       -- 'happy'
```

## Schema names

On multi-schema engines, schemas complete in FROM and `public.users` resolves in FROM, JOIN, UPDATE, INSERT INTO and CREATE INDEX.

Where the hierarchy is database, schema, table (Snowflake, BigQuery), every segment completes and a schema you have not opened in the sidebar is fetched on demand:

```sql theme={null}
SELECT * FROM ANALYTICS_|                      -- databases
SELECT * FROM ANALYTICS_PROD.|                 -- schemas
SELECT * FROM ANALYTICS_PROD.DBT_MARTS.|       -- tables in that schema
SELECT * FROM ANALYTICS_PROD.DBT_MARTS.ORDERS o WHERE o.|  -- columns
```

## Favorite keywords

A favorite with a keyword, stored in the database or set by `@keyword` frontmatter in a linked file, appears as a top-priority match. Type the keyword, accept it, and the favorite's full SQL replaces it inline. A `;;` in that SQL says where the cursor lands afterwards. See [Favorites](/features/favorites#cursor-placement).

## MongoDB

MongoDB connections complete MQL, so the popup follows the shape of the query rather than SQL clauses:

```js theme={null}
db.|                                  // collections, plus getCollectionNames(), createCollection(), …
db.users.|                            // find(), aggregate(), updateOne(), insertMany(), …
db.users.find({ |                     // field names, then $eq, $gt, $in, $exists, $regex, …
db.users.find({}, { |                 // field names, then $slice, $elemMatch, $meta
db.users.updateOne({}, { |            // $set, $unset, $inc, $push, $addToSet, …
db.users.updateOne({}, [{ |           // the six stages an update pipeline allows
db.orders.aggregate([{ |              // $match, $group, $lookup, $unwind, $facet, …
db.orders.aggregate([{ $group: { |    // $sum, $avg, $first, $push, and the expression operators
```

`$set` and `$unset` mean different things as an update operator and as a pipeline stage; the description shown is whichever applies at the cursor.

Field names come from a sample of the collection's documents, nested paths included, so `address: { city, zip }` offers `address`, `address.city` and `address.zip`. Objects inside an array contribute paths too, and shallower fields sort first. The sample is cached per collection and cleared when you switch database or refresh the connection.

Comments suppress completion, and a brace or bracket inside a string literal does not open a document.

## My new table does not complete

Table and column names are cached at connect, so a migration or a `CREATE TABLE` run from a terminal stays invisible until the cache reloads. Press `Cmd+R` (**Database > Refresh**), or right-click the sidebar's Tables header and choose **Refresh**. Switching databases reloads it too.

## Large files

Completion works on files of any size, multi-megabyte dumps included. Past 500 KB only a 10 KB window around the cursor is read, so suggestions follow the statements near you rather than the whole file.
