mapbench
Contents

Documentation → How-to guides

Using the SQL Workbench

The Workbench is a tabbed workspace where you write spatial SQL, preview the rows it returns, and turn a query you want to keep into a mappable dataset. This page covers how to use the tool. For the SQL itself, including the dialect, the geometry column and joins across sources, see Query and model data with SQL.

The layout

Open SQL Workbench from the sidebar. Each open model is a tab across the top, and the selected tab fills the work area:

  • A toolbar with the model's name, Preview, the main Run (or Save & Run) button, and a ⋯ menu for everything else.
  • An input chip row with the SQL editor below it, across the full width. Each input has a short alias, which is the table name you use after FROM. + Add input opens the dataset picker.
  • A results dock underneath, showing the rows your query returned with the result map beside them.

Preview, Run and Save

Most of the time you use two buttons: one to check what your SQL returns, and one to build the result as a dataset. The other settings are under ⋯.

ActionWhat it doesCreates
Preview Runs the SQL and shows the rows it returns. It includes unsaved edits, so you can use it repeatedly while you write a query. nothing
Run (a new model) Names the output and builds it as a dataset. This is the only time you're asked for a name and a layer ID. The layer ID is written into the tiles and can't be changed afterwards. a new, tiled dataset
Save & Run (a saved model) Saves the SQL change and re-tiles the output. The dataset keeps its id, so its styling, map memberships and published links carry over. replaces the output
Save (in ⋯) Saves an SQL edit to a saved model without re-tiling, for when you don't want to start a tiling job yet. nothing new

A draft has no name until you run it, so you can write and preview a query you might not keep. Until then the tab is titled New model. To name it earlier, double-click the tab. Otherwise the Run dialog asks for a name.

Keyboard shortcuts

The shortcuts follow the usual SQL console convention: ⌘ or Ctrl with Enter previews, and adding Shift runs the model.

ActionmacOSWindows / Linux
Preview: run the SQL and show rows ⌘ Enter Ctrl + Enter
Run / Save & Run: build the dataset ⌘ ⇧ Enter Ctrl + Shift + Enter
Save: save an SQL edit ⌘ S Ctrl + S

The shortcuts work anywhere in the editor and apply to the tab you have open. On a new model, ⌘ ⇧ Enter opens the same Run dialog as the button, so you still name the output before anything is created.

Preview and Last run

Once a model has run, the rows dock has two tabs:

  • Preview runs the SQL currently in the editor, including edits you haven't run yet.
  • Last run shows the rows in the built dataset, which is what your maps read. If a run failed, its error and job log appear here.

The two differ when you have previewed an edit but not run it, when a run failed, or when the last successful run used older SQL. A new model only has Preview, because it hasn't been run yet.

Tabs and drafts

You can open as many models as you like, each in its own tab.

  • Unsaved SQL is kept, both for drafts and for edits to saved models. It survives a page reload and switching projects, and is stored separately for each project. A • on a tab means it has unsaved work.
  • Only the tab you have open shows its map. The other tabs keep their editor state but don't hold a live map, so you can keep a dozen tabs open without the browser unloading them.

The result map

The result map appears after a successful run. It shows the tiled output with that dataset's styling. From the ⋯ menu you can place it beside the results (the default, which stacks it below the editor), beside the editor (a right-hand split with more room for checking the map), or set it to hidden. While a run is in progress, the map shows the previous result until the new one finishes.

See also