Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
neelasha23 committed Nov 24, 2023
1 parent 63f68ff commit 5059794
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions doc/api/magic-sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,3 +359,40 @@ LIMIT 3
```{code-cell} ipython3
%sql --file my-query.sql
```

# Parameterizing arguments

JupySQL supports variable expansion of arguments in the form of {{variable}}. This allows the user to specify arguments with placeholders that can be replaced by variables dynamically. The arguments supported are `section`, `close`, `alias`, `save` and `with`.

Let's see an example of creating a connection using an alias and closing the same through variable substitution.

```{code-cell} ipython3
alias = "db-four"
%sql sqlite:///db_four.db --alias {{alias}}
```

```{code-cell} ipython3
%sql --close {{alias}}
```

Let's see another example using `save`:

```{code-cell} ipython3
snippet = "larger_than_two"
%%sql --save {{snippet}} --no-execute
SELECT x, y
FROM my_data
WHERE x > 2
```

```{code-cell} ipython3
%%sql --save {{snippet}}
SELECT *
FROM {{snippet}}
```




0 comments on commit 5059794

Please sign in to comment.