【问题标题】:Is there a way to use SQL syntax highlighting in triple-quoted literals in Jupyter notebook?有没有办法在 Jupyter Notebook 的三引号文字中使用 SQL 语法高亮显示?
【发布时间】:2022-12-03 15:06:01
【问题描述】:

I\'m doing ETL development using pyspark in a Jupyter notebook. I generally prefer to use SQL queries instead of pyspark functions, since I find SQL more readable than pyspark functions most of the time. However, SQL queries in Python scripts take the form of literal strings, which are treated as, well, strings, not code, when it comes to coloring the text.

To make development easier for myself, I want to color triple-quoted literal strings the same way that SQL code would be highlighted if it stood on its own in an IDE or text editor.

Is this possible?

For example, take the following code:

print(\'Hello world\')
sql = \"\"\"
      SELECT myid, myname, CAST(mydate AS DATE)
      FROM myschema.mytable
      WHERE something
      \"\"\"
execute_sql(sql)

If possible, I would like that string to appear like so, while not changing it\'s characteristics of being a string:

标签: python sql pyspark jupyter-notebook


【解决方案1】:
猜你喜欢
  • 2016-05-10
  • 1970-01-01
  • 2019-07-23
  • 1970-01-01
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 1970-01-01
  • 2021-01-24
相关资源
最近更新 更多