F-strings

F-strings are a readable approach to building new strings from existing strings & variables.

PRQL

  1. from employees
  2. select full_name = f"{first_name} {last_name}"

SQL

  1. SELECT
  2. CONCAT(first_name, ' ', last_name) AS full_name
  3. FROM
  4. employees

This can be much easier to read for longer strings, relative to the SQL approach:

PRQL

  1. from web
  2. select url = f"http{tls}://www.{domain}.{tld}/{page}"

SQL

  1. SELECT
  2. CONCAT(
  3. 'http',
  4. tls,
  5. '://www.',
  6. domain,
  7. '.',
  8. tld,
  9. '/',
  10. page
  11. ) AS url
  12. FROM
  13. web

Note that currently interpolations can only contain plain variable names and not whole expressions like Python, so this won’t work:

PRQL

  1. from tracks
  2. select length_str = f"{length_seconds / 60} minutes"

Error

  1. Error:
  2. ╭─[:2:38]
  3. 2 select length_str = f"{length_seconds / 60} minutes"
  4. ╰── interpolated string expected one of ".", ":" or "}", but found " "
  5. ───╯

Roadmap

In the future, f-strings may incorporate string formatting such as datetimes, numbers, and padding. If there’s a feature that would be helpful, please post an issue.