Strings

String literals can use any matching odd number of either single or double quotes:

PRQL

  1. from artists
  2. derive {
  3. single = 'hello world',
  4. double = "hello world",
  5. double_triple = """hello world""",
  6. }

SQL

  1. SELECT
  2. *,
  3. 'hello world' AS single,
  4. 'hello world' AS double,
  5. 'hello world' AS double_triple
  6. FROM
  7. artists

Quoting and escape characters

To quote a string containing quote characters, use the “other” type of quote, or use the escape character \, or use more quotes.

PRQL

  1. from artists
  2. select {
  3. other = '"hello world"',
  4. escaped = "\"hello world\"",
  5. triple = """I said "hello world"!""",
  6. }

SQL

  1. SELECT
  2. '"hello world"' AS other,
  3. '"hello world"' AS escaped,
  4. 'I said "hello world"!' AS triple
  5. FROM
  6. artists

Strings can contain any escape character sequences defined by the JSON standard.

PRQL

  1. from artists
  2. derive escapes = "\tXYZ\n \\ " # tab (\t), "XYZ", newline (\n), " ", \, " "
  3. derive world = "\u{0048}\u{0065}\u{006C}\u{006C}\u{006F}" # "Hello"
  4. derive hex = "\x48\x65\x6C\x6C\x6F" # "Hello"
  5. derive turtle = "\u{01F422}" # "🐢"

SQL

  1. SELECT
  2. *,
  3. ' XYZ
  4. \ ' AS escapes,
  5. 'Hello' AS world,
  6. 'Hello' AS hex,
  7. '🐢' AS turtle
  8. FROM
  9. artists

Other string formats

  • F-strings - Build up a new string from a set of columns or values.
  • R-strings - Include the raw characters of the string without any form of escaping.
  • S-strings - Insert SQL statements directly into the query. Use when PRQL doesn’t have an equivalent facility.

Warning

Currently PRQL allows multiline strings with either a single character or multiple character quotes. This may change for strings using a single character quote in future versions.

Note

These escape rules specify how PRQL interprets escape characters when compiling strings to SQL, not necessarily how the database will interpret the string. Dialects interpret escape characters differently, and PRQL doesn’t currently account for these differences. Please open issues with any difficulties in the current implementation.

Escape sequences

Unless an r prefix is present, escape sequences in string literals are interpreted according to rules similar to those used by Standard C. The recognized escape sequences are:

Escape SequenceMeaning
\Backslash ()
\’Single quote (’)
\”Double quote (“)
\bBackspace
\fFormfeed
\nASCII Linefeed (LF)
\rASCII Carriage Return (CR)
\tASCII Horizontal Tab (TAB)
\xhhCharacter with hex value hh
\u{xxxx}Character with hex value xxxx