# SQL syntax hightlighting

**URL:** <https://discourse.julialang.org/t/sql-syntax-hightlighting/103845>\
**Category:** General Usage\
**Tags:** dataframes, vscode, sql, odbc\
**Created:** [September 14, 2023, 10:55am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845 "2023-09-14T10:55:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [September 14, 2023, 10:55am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/1 "2023-09-14T10:55:14Z")

</div>

> **[SQL Server (mssql) - Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=ms-mssql.mssql)**
>
> Extension for Visual Studio Code - Develop Microsoft SQL Server, Azure SQL Database and SQL Data Warehouse everywhere

This provides syntax highlighting and auto-completion of SQL in VS Code.

Would it be possible to have a section in a .jl file that VS Code treats as SQL  
(for syntax highlight and autocompletion) ? Then convert the result to a Julia DataFrame.  
Something like

```julia
@SQL_Block my_connection_string

select * from my_table

end |> DataFrame

```

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [September 14, 2023, 11:19am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/2 "2023-09-14T11:19:55Z")

</div>

Typically, you’d use a string macro for this, which already gives you the correct syntax highlighting:  
 ![image](https://global.discourse-cdn.com/julialang/original/3X/a/2/a2fa8c85fe059851709508383451147f911d4f2c.png)

I’m not sure if you get the auto completions provided by the `SQL Server` extension, but I highly doubt it. This is not something we can implement on our end.

---

<div class="post-metadata">

**Author:** ![jd-foster](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jd-foster/32/35824_2.png) [@jd-foster](https://discourse.julialang.org/u/jd-foster)\
**Post date:** [September 14, 2023, 11:23am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/3 "2023-09-14T11:23:04Z")

</div>

For the last part of your question, you might look into [GitHub - wookay/Octo.jl: Octo.jl 🐙 is an SQL Query DSL in Julia](https://github.com/wookay/Octo.jl)

---

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [September 14, 2023, 11:33am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/4 "2023-09-14T11:33:22Z")

</div>

Thanks I wasn’t aware of SQL" "

---

<div class="post-metadata">

**Author:** ![Lincoln\_Hannah](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lincoln_hannah/32/19198_2.png) [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Post date:** [September 15, 2023, 1:03am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/5 "2023-09-15T01:03:34Z")

</div>

This initially gives `error @sql_str not defined `.

Adding `macro sql_str(x) x end` makes it work but I lose the ability to put $variables in the string.

Is there a way to use $variables within a sql"“” “”" string ?

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [September 15, 2023, 8:58am UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/6 "2023-09-15T08:58:49Z")

</div>

I’d recommend using something like [GitHub - JuliaComputing/SQLStrings.jl: Safe interpolations for SQL query strings](https://github.com/JuliaComputing/SQLStrings.jl) instead.

---

<div class="post-metadata">

**Author:** ![Jake](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jake/32/46007_2.png) [@Jake](https://discourse.julialang.org/u/Jake)\
**Post date:** [September 15, 2023, 1:25pm UTC](https://discourse.julialang.org/t/sql-syntax-hightlighting/103845/7 "2023-09-15T13:25:15Z")

</div>

It is also worth looking at [FunSQL.jl](https://github.com/MechanicalRabbit/FunSQL.jl)
