Skip to content

Commit aa4a07f

Browse files
msullivananbuzin
authored andcommitted
Reference documentation for string interpolation (#8244)
1 parent ee104ed commit aa4a07f

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

docs/stdlib/string.rst

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ Strings
102102

103103
A unicode string of text.
104104

105-
Any other type (except :eql:type:`bytes`) can be
105+
Most primitive types (except :eql:type:`bytes`) can be
106106
:eql:op:`cast <cast>` to and from a string:
107107

108108
.. code-block:: edgeql-repl
@@ -163,6 +163,24 @@ Strings
163163
This type is subject to `the Postgres maximum field size`_
164164
of 1GB.
165165

166+
.. versionadded:: 6.0
167+
168+
Regular strings may use ``\(expr)`` to interpolate the value of
169+
``expr`` into the string. The value will be cast to ``str`` if it
170+
is not already. For example:
171+
172+
.. code-block:: edgeql-repl
173+
174+
db> select '1 + 1 = \(1+1)';
175+
{'1 + 1 = 2'}
176+
db> select User { name := '\(.first_name) \(.last_name)' };
177+
{
178+
default::User {
179+
name := 'Keanu Reeves',
180+
},
181+
...
182+
}
183+
166184
167185
.. lint-off
168186
.. _the Postgres maximum field size: https://wiki.postgresql.org/wiki/FAQ#What_is_the_maximum_size_for_a_row.2C_a_table.2C_and_a_database.3F>
@@ -475,7 +493,7 @@ Strings
475493

476494
If *trim* specifies more than one character they will be removed from
477495
both ends of the string regardless of the order in which they appear.
478-
This is the same as applying
496+
This is the same as applying
479497
:eql:func:`str_trim_start` and :eql:func:`str_trim_end`.
480498

481499
.. code-block:: edgeql-repl
@@ -698,7 +716,7 @@ Strings
698716
{'21st century'}
699717
700718
.. note::
701-
719+
702720
If you want to use literal text in your format string, it's best to
703721
enclose it in double quotes as shown above with ``of`` and
704722
``century``.
@@ -759,7 +777,7 @@ Strings
759777
A version of ``std::to_str`` exists which operates on arrays but has
760778
been deprecated; :eql:func:`array_join` should be used instead.
761779

762-
A :eql:type:`bytes` value can be converted to a :eql:type:`str` using
780+
A :eql:type:`bytes` value can be converted to a :eql:type:`str` using
763781
UTF-8 encoding. Returns an InvalidValueError if input UTF-8 is invalid.
764782

765783
.. code-block:: edgeql-repl

0 commit comments

Comments
 (0)