Pasting SQL into Obsidian

Things I have tried

What I’m trying to do

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?

Hi @aagha !

Here’s how I paste SQL into Obsidian:

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.

Hope this helps!

Craig

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.