Query parameters

A parameter is a placeholder in your SQL whose value you fill in before a run. Use one when you run the same query again with different inputs, such as a customer ID or a date, without editing the SQL each time.

Add a parameter

  1. Put the cursor where the value belongs, for example after WHERE order_date >= .
  2. Press Ctrl+P, click the braces button in the editor toolbar (its tooltip reads Add Parameter (Ctrl+P)), or click Add parameter in the Parameters strip under the editor.
  3. In the New parameter popover, enter a Name, such as user_id. Choose a Type, and optionally enter a Value.
  4. Click Add, or press Enter.

Add writes the {name:Type} placeholder into the SQL at the cursor. A parameter reaches the query only through its placeholder.

sql
SELECT * FROM <database>."<table>" WHERE order_date >= {from:Date}
Tip

You can also type {name:Type} straight into the SQL. Its chip appears in the Parameters strip as From query.

Where a parameter comes from

Every chip carries a small dot. Hover over the chip to read where the parameter came from, and open it for the short explanation:

If the same name comes from more than one place, you still see one chip: the placeholder in the SQL wins over a required parameter, and a required parameter wins over a manual one.

Some screens open the Editor in a popup with parameters of their own. There, Add parameter is locked and Ctrl+P does nothing, and the origin notes are hidden, because the popup decides which parameters exist. An info icon beside the strip title can explain the popup's own rules.

Fill in the values

The Parameters strip shows one chip for each parameter, and a badge beside its title counts them: it reads {n} parameter(s), and turns red with {n} missing while a required value is still empty. Each chip shows the parameter's name, type and value.

  1. Click the chip.
  2. Type the value in the Value field.
  3. Press Enter, or click Save.
  4. Run the query. See Run your first query.

A chip with no value shows empty; a Required chip whose value is missing shows required and turns red. The popover shows the {name:Type} text with a button titled Copy parameter format, and a From query or Required chip also shows a lock icon and the note about its origin.

Your values are saved with the console

Parameters and their values save with the console a moment after you change them, and straight away when you switch consoles. When you reopen the console, the values are still there. Consoles are private to you. See Consoles, saving and history.

Each run in the console's History tab shows the query with the values it used, so you can check what ran. See Console history and run log.

Remove a parameter

  1. Click the chip of a Manual parameter.
  2. Click Remove.

Remove takes the parameter out of the editor's parameter list; it does not change your SQL text.

A From query chip has no Remove button. To remove that parameter, delete its {name:Type} placeholder from the SQL; the chip disappears with it. A Required parameter comes from the screen that opened the editor and cannot be removed here.

Parameter settings

SettingWhat it doesDefault
NameThe name inside the placeholder. Letters, digits and underscores only, starting with a letter or underscore. Required.None
TypeThe type the database converts the value to. Pick it from the searchable list.String
ValueThe value used for the run. You can leave it empty and fill it in on the chip later.Empty, shown as empty

Who can use parameters

Parameters need no permission of their own. You use them wherever you can open the Editor. See Editor for who can open it.

Know these limits

Questions, answered

What syntax do parameters use?

Write {name:Type}, for example {customer_id:UInt64} or {from:Date}. You choose the name. The type comes after the colon; if you leave it out, the parameter counts as String.

Do I put quotes around a String parameter?

No. Write {name:String} without quotes, and type the text as it is in the Value field. The database converts the value to the type of the placeholder.

Why does the popover say "Must start with a letter or underscore"?

The name may use only letters, digits and underscores, and must start with a letter or underscore. The same message appears for any name that breaks these rules, including one with a hyphen. Use user_id instead of user-id.

How do I remove a parameter?

For a Manual parameter, click Remove on its chip. For a From query parameter, delete its placeholder from the SQL; its chip disappears with it. A Required parameter cannot be removed here: it comes from the screen that opened the editor.

Are my parameter values kept?

Yes. Parameters and their values are saved with the console, so they are there when you come back to it. Consoles are private to you. See Consoles, saving and history.

Can I use the same parameter twice in a query?

Yes. Write the same {name:Type} placeholder in both places. The strip shows one chip, and its value fills both places.

Which types can I choose?

String, UInt8, UInt16, UInt32, UInt64, Int8, Int16, Int32, Int64, Float32, Float64, Date, DateTime, DateTime64, Bool, UUID, IPv4 and IPv6. String is the default.

What do the dots on the chips mean?

The dot's colour and hover text show where the parameter came from: From query for a placeholder in your SQL, Required for a parameter the screen that opened the editor needs, and Manual for one you added. Open the chip to read the explanation.

Why can't I run the query until I fill in a parameter?

A parameter marked Required comes from the screen that opened the editor, and the run stays unavailable until every required parameter has a value. Hover over the run button to see Fill required parameters: followed by the names that are still missing.

Why has the Parameters strip disappeared?

The strip shows only while the console has a parameter. When the last one is gone, it hides. Press Ctrl+P to add a parameter; the strip returns with the New parameter form, showing None - add one or use {name:Type} in the query until you click Add. On a screen that locks the parameter list, the strip with no parameters reads No parameters provided.

Does autocomplete suggest my parameters?

Yes. While you type, autocomplete offers your parameters in their full {name:Type} form. See Write and check SQL.