Skip to content

Commit 8a012ed

Browse files
committed
Add new operators and string expression functions
1 parent f59196a commit 8a012ed

File tree

2 files changed

+89
-3
lines changed

2 files changed

+89
-3
lines changed

docs/user_manual/expressions/expression_help/Operators.rst

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,15 @@ Multiplication of two values
5757
\+
5858
..
5959
60-
Addition of two values. If one of the values is NULL the result will be NULL.
60+
Addition of two values or concatenation of two strings.
61+
62+
63+
64+
For numeric and datetime operations if either value is NULL the result will be NULL.
65+
66+
67+
68+
For string concatenation NULL values from fields are treated as empty strings. Use the || operator instead if NULL propagation for strings is required.
6169

6270
.. list-table::
6371
:widths: 15 85
@@ -70,6 +78,8 @@ Addition of two values. If one of the values is NULL the result will be NULL.
7078
* - Examples
7179
- * ``5 + 4`` → 9
7280
* ``5 + NULL`` → NULL
81+
* ``'5' + NULL`` → NULL
82+
* ``'5' + "name"`` → '5' (if value in "name" field is NULL) or a concatenation of the two strings
7383
* ``'QGIS ' + 'ROCKS'`` → 'QGIS ROCKS'
7484
* ``to_datetime('2020-08-01 12:00:00') + '1 day 2 hours'`` → 2020-08-02T14:00:00
7585

@@ -595,7 +605,7 @@ Joins two values together into a string.
595605

596606

597607

598-
If one of the values is NULL the result will be NULL. See the CONCAT function for a different behavior.
608+
If one of the values is NULL the result will be NULL. See the **concat** function for an alternative concatenation behavior.
599609

600610
.. list-table::
601611
:widths: 15 85

docs/user_manual/expressions/expression_help/String.rst

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,78 @@
66
in the resources/function_help/json/ folder in the
77
qgis/QGIS repository.
88
9+
.. _expression_function_String_backslash_quote:
10+
11+
\\' (quote character)
12+
.....................
13+
14+
Inserts a literal single quote character in a string.
15+
16+
.. list-table::
17+
:widths: 15 85
18+
19+
* - Syntax
20+
- \\' (quote character)
21+
* - Examples
22+
- * ``'It\'s working'`` → 'It's working'
23+
24+
25+
.. end_\\'_(quote_character)_section
26+
27+
.. _expression_function_String_backslash_backslash:
28+
29+
\\\\ (backslash character)
30+
..........................
31+
32+
Inserts a literal backslash character in a string.
33+
34+
.. list-table::
35+
:widths: 15 85
36+
37+
* - Syntax
38+
- \\\\ (backslash character)
39+
* - Examples
40+
- * ``'C:\\Users\\Name'`` → 'C:\\Users\\Name'
41+
42+
43+
.. end_\\\\_(backslash_character)_section
44+
45+
.. _expression_function_String_backslash_n:
46+
47+
\\n (newline character)
48+
.......................
49+
50+
Inserts a newline character in a string literal.
51+
52+
.. list-table::
53+
:widths: 15 85
54+
55+
* - Syntax
56+
- \\n (newline character)
57+
* - Examples
58+
- * ``'Hello\nWorld'`` → a string with a newline between 'Hello' and 'World':<br>Hello<br>World
59+
60+
61+
.. end_\\n_(newline_character)_section
62+
63+
.. _expression_function_String_backslash_t:
64+
65+
\\t (tab character)
66+
...................
67+
68+
Inserts a tab character in a string literal.
69+
70+
.. list-table::
71+
:widths: 15 85
72+
73+
* - Syntax
74+
- \\t (tab character)
75+
* - Examples
76+
- * ``'Name\tAge\tCity'`` → Name Age City (tabs between the words)
77+
78+
79+
.. end_\\t_(tab_character)_section
80+
981
.. _expression_function_String_ascii:
1082

1183
ascii
@@ -51,7 +123,11 @@ Returns the character associated with a unicode code.
51123
concat
52124
......
53125

54-
Concatenates several strings to one. NULL values are converted to empty strings. Other values (like numbers) are converted to strings.
126+
Concatenates several values to a single string. NULL values are converted to empty strings. Other values (like numbers) are converted to strings.
127+
128+
129+
130+
See the **||** function for an alternative concatenation behavior.
55131

56132
.. list-table::
57133
:widths: 15 85

0 commit comments

Comments
 (0)