prql icon indicating copy to clipboard operation
prql copied to clipboard

Support escaping quotes inside strings & S-strings

Open mklopets opened this issue 2 years ago • 3 comments

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

mklopets avatar Dec 03 '22 23:12 mklopets

What about using multiple quotes? https://prql-lang.org/book/language-features/strings.html

max-sixty avatar Dec 04 '22 00:12 max-sixty

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!

mklopets avatar Dec 04 '22 16:12 mklopets

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.

max-sixty avatar Dec 04 '22 22:12 max-sixty

Consolidating into https://github.com/PRQL/prql/issues/1682, which has a good case of this

max-sixty avatar Jun 02 '23 08:06 max-sixty

For any future travelers — strings now support escaping. r"foo" is a raw string that doesn't use escape characters.

max-sixty avatar Aug 08 '23 02:08 max-sixty