Skip to content

A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.

docs: escaping sql backets (#3042)

Myles Scolnick6b58c67d378a
diff --git a/docs/faq.md b/docs/faq.md
index c27d036215..708adb6f9d 100644
--- a/docs/faq.md
+++ b/docs/faq.md
@@ -22,6 +22,7 @@
- [How do I create an output with a dynamic number of UI elements?](#faq-dynamic-ui-elements)
- [Why aren't my `on_change` handlers being called?](#faq-on-change-called)
- [Why are my `on_change` handlers in an array all referencing the last element?](#faq-on-change-last)
+ - [Why aren't my brackets in SQL working?](#faq-sql-brackets)
- [How do I restart a notebook?](#faq-restart)
- [How do I reload modules?](#faq-reload)
- [How does marimo treat type annotations?](#faq-annotations)
@@ -82,7 +83,6 @@ In addition, marimo notebooks can serialize package requirements inline;
marimo runs these "sandboxed" notebooks in temporary virtual environments,
making them [reproducible down to the packages](/guides/editor_features/package_management.md).
-
**Maintainability.**
marimo notebooks are stored as pure Python programs (`.py` files). This lets you
version them with Git; in contrast, Jupyter notebooks are stored as JSON and
@@ -225,10 +225,8 @@ your notebook state and automatically marks cells as stale when appropriate.
Interactive UI elements like sliders are available in `marimo.ui`.
-- Assign the UI element to a global variable (`slider = mo.ui.slider(0,
- 100)`)
-- Include it in the last expression of a cell to display
-it (`slider` or `mo.md(f"Choose a value: {slider}")`)
+- Assign the UI element to a global variable (`slider = mo.ui.slider(0, 100)`)
+- Include it in the last expression of a cell to display it (`slider` or `mo.md(f"Choose a value: {slider}")`)
- Read its current value in another cell via its `value` attribute (`slider.value`)
_When a UI element bound to a global variable is interacted with, all cells
@@ -258,7 +256,7 @@ example,
form = marimo.ui.text_area().form()
```
- When wrapped in a form, the
+When wrapped in a form, the
text area's value will only be sent to Python when you click the submit button.
Access the last submitted value of the text area with `form.value`.
@@ -407,6 +405,18 @@ array
This is necessary because [in Python, closures are late-binding](https://docs.python-guide.org/writing/gotchas/#late-binding-closures).
+<a name="faq-sql-brackets"></a>
+
+### Why aren't my SQL brackets working?
+
+Our "SQL" cells are really just Python under the hood to keep notebooks as pure Python scripts. By default, we use `f-strings` for SQL strings, which allows for parameterized SQL like `SELECT * from table where value < {min}`.
+
+To escape real `{`/`}` that you don't want parameterized, use double `{{...}}`:
+
+```sql
+SELECT unnest([{{'a': 42, 'b': 84}}, {{'a': 100, 'b': NULL}}]);
+```
+
<a name="faq-annotations"></a>
### How does marimo treat type annotations?
diff --git a/docs/guides/working_with_data/sql.md b/docs/guides/working_with_data/sql.md
index 95d41bc79c..672da77ca7 100644
--- a/docs/guides/working_with_data/sql.md
+++ b/docs/guides/working_with_data/sql.md
@@ -123,6 +123,16 @@ SELECT * FROM read_parquet('path/to/example.parquet');
For a full list you can check out the [duckdb extensions](https://duckdb.org/docs/extensions/overview).
You can also check out our [examples on GitHub](https://github.com/marimo-team/marimo/tree/main/examples/sql).
+## Escaping SQL brackets
+
+Our "SQL" cells are really just Python under the hood to keep notebooks as pure Python scripts. By default, we use `f-strings` for SQL strings, which allows for parameterized SQL like which allows for parameterized SQL like `SELECT * from table where value < {min}`.
+
+To escape real `{`/`}` that you don't want parameterized, use double `{{...}}`:
+
+```sql
+SELECT unnest([{{'a': 42, 'b': 84}}, {{'a': 100, 'b': NULL}}]);
+```
+
## Interactive tutorial
For an interactive tutorial, run