prql
prql copied to clipboard
Support escaping quotes inside strings & S-strings
It's not always possible (or just convenient) to switch to the "other quotes" (or, as Max pointed out, triple quotes). What if you need both at the same time?
I believe this query:
from x | filter s"something something \"asd\""
should be valid PRQL and equivalent to this one:
from x | filter s'something something "asd"'
Backslashes would likely be the most standard way of solving this.
Currently, backslashes in s-strings cause a different kind of weirdness:
filter s'foo\bar'
...compiles to this (notice the spaces):
WHERE
foo \ bar
What about using multiple quotes? https://prql-lang.org/book/language-features/strings.html
That works precisely until the moment that someone needs to use 3 quotes inside the S-string for some reason. 😄
For non-Python folks, triple-quotes probably aren't the intuitive solution either, whereas backslash-escaping is universal.
Now that I think about it, exactly the same problem exists in any string literals in PRQL, not just in s-strings!
That works precisely until the moment that someone needs to use 3 quotes inside the S-string for some reason. 😄
But then you can use 5 quotes!
Though obv I get your point — having a way of escaping things is useful.
It's quite simple to just have all strings be "raw", but no opposition if someone wants to do this. Possibly we should think about how to handle \n and similar escape sequences too.
Consolidating into https://github.com/PRQL/prql/issues/1682, which has a good case of this
For any future travelers — strings now support escaping. r"foo" is a raw string that doesn't use escape characters.