I’m often sent or am writing large SQL queries with multiple nested selects that I’d like to document and keep in Obsidian.
However, when I paste sql using ‘>’, I spend a lot of time indenting and removing spaces from all the subsequent SQL so it fits inside a code block. Furthermore, I lose all the formatting, so everything is left-aligned.
Is there a way of simply and nicely/cleanly pasting SQL directly into Obsidian and keeping its formatting?
First, I create a code block that looks like the following:
```sql
```
Then I copy the SQL query from my source (say, a web page). Then I paste the text --unformatted – into the code block using CTRL-SHIFT-V (on Linux and Windows, might be different on Mac). Now the text block looks like this:
```sql
SELECT empid,
name,
dno,
salary,
job,
CORR(SYSDATE - joiningdate, salary) OVER () AS my_corr_val
FROM employee;
```
Pasting unformatted using CTRL-SHIFT-C is important so that Obsidian doesn’t try to re-format the code. Pasting using the regular CTRL-C will cause the code to have a bunch of newlines and other decorations.