SQL syntax highlighting#

syntax

You can enable SQL syntax highlighting via Jupyterlab-lsp.

Installation#

Optionally, create a new environment with JupyterLab installed:

conda create --name jupysqlenv python=3.10 jupyterlab --yes --channel conda-forge
conda activate jupysqlenv

JupyterLab-lsp requires Node, if you don’t have it, you can install it with conda:

conda install --channel conda-forge nodejs --yes

Now, install the rewuired dependencies using pip:

pip install jupyter-lsp jupyterlab-lsp python-language-server --quiet

To run SQL queries on Jupyter, install JupySQL:

pip install jupysql --quiet

Finally, add the SQL language server:

jlpm add --dev sql-language-server

Now, start Jupyter Lab, you’ll see this in the bottom bar:

init

After a few seconds, LSP should be fully initialized and you’ll get SQL syntax highlighting!

running

Querying#

Here’s some sample code to test it (requires: pip install duckdb-engine)

Note that syntax highlighting won’t work on this page, but it’ll work on Jupyter.

%load_ext sql
%sql duckdb://
%%sql
INSTALL httpfs
*  duckdb://
Done.
Success
%%sql 
SELECT *
FROM "https://raw.githubusercontent.com/mwaskom/seaborn-data/master/penguins.csv"
LIMIT 3
*  duckdb://
Done.
species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g sex
Adelie Torgersen 39.1 18.7 181 3750 MALE
Adelie Torgersen 39.5 17.4 186 3800 FEMALE
Adelie Torgersen 40.3 18.0 195 3250 FEMALE