-
Notifications
You must be signed in to change notification settings - Fork 784
Add documentation for the LPAD and RPAD OQL functions #11190
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: development
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -692,10 +692,12 @@ These are the currently supported functions: | |
| * LENGTH | ||
| * LOCATE | ||
| * LOWER | ||
| * LPAD | ||
| * RANGEBEGIN | ||
| * RANGEEND | ||
| * REPLACE | ||
| * ROUND | ||
| * RPAD | ||
| * UPPER | ||
|
|
||
| ### CAST{#cast} | ||
|
|
@@ -1329,6 +1331,57 @@ SELECT * FROM Sales.Customer WHERE LOWER(LastName) = 'doe' | |
| This query can no longer take advantage of an index for `LastName` for comparison, resulting in a performance decrease. | ||
| {{% /alert %}} | ||
|
|
||
| ### LPAD {#lpad-function} | ||
|
|
||
| #### Description | ||
|
|
||
| Pads a string on the left side with a specified character to reach a target length. If no character is specified for padding, the space character is used. | ||
|
|
||
| {{% alert color="info" %}} | ||
| This function was introduced in Mendix version 11.12.0. | ||
| {{% /alert %}} | ||
|
|
||
| #### Syntax | ||
|
|
||
| ```sql | ||
| LPAD ( expression , length_expression [, pad_expression ] ) | ||
| ``` | ||
|
|
||
| #### expression | ||
|
|
||
| `expression` specifies the expression of type `string` to pad. | ||
|
|
||
| #### length_expression | ||
|
|
||
| `length_expression` specifies the length of the resulting string. The expression must be of type `integer` or `long` | ||
|
|
||
| {{% alert color="info" %}} | ||
| If `length_expression` is smaller than the length of `expression`, this function truncates it. This behavior is database specific. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Truncates the right side, even though we are doing
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Weirdly, yes. We were just as confused when implementing. The only exception is HSQLDB, which does the right thing, but possibly by accident given how special it is. |
||
| {{% /alert %}} | ||
|
|
||
| #### pad_expression | ||
|
|
||
| `pad_expression` is an optional parameter that specifies the character or string to pad with. If not specified, the space character is used. | ||
|
passalaqua marked this conversation as resolved.
|
||
|
|
||
| #### Examples | ||
|
|
||
| ```sql | ||
| SELECT LPAD('hello', 10) AS padded FROM Sales.Order | ||
| ``` | ||
|
|
||
| | padded | | ||
| |:-----------| | ||
| | hello | | ||
|
Comment on lines
+1372
to
+1374
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suppose we can change the query to
The resulting string would be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could also just render the result as Or something similar and indicate |
||
|
|
||
|
|
||
| ```sql | ||
| SELECT LPAD('hello', 10, 'x') AS padded FROM Sales.Order | ||
| ``` | ||
|
|
||
| | padded | | ||
| |:-----------| | ||
| | xxxxxhello | | ||
|
|
||
|
Comment on lines
+1377
to
+1384
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it worth an example with a string SELECT LPAD('hello', 10, 'abc') AS padded FROM Sales.Order
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably a good idea. I can write it as part of the same query (shorter page) or as a separate example (clearer). Which one do you prefer? |
||
| ### Ranges in Datasets | ||
|
|
||
| {{% alert color="info" %}} | ||
|
|
@@ -1507,6 +1560,57 @@ SELECT ROUND((Price : 7), 2) as RoundedPrice, Price : 7 FROM Sales.Order | |
| | 0.33 | 3.33333333 | | ||
| | 1.17 | 1.17142857 | | ||
|
|
||
| ### RPAD {#rpad-function} | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comments as for LPAD |
||
|
|
||
| #### Description | ||
|
|
||
| Pads a string on the right side with a specified character to reach a target length. If no character is specified for padding, the space character is used. | ||
|
|
||
| {{% alert color="info" %}} | ||
| This function was introduced in Mendix version 11.12.0. | ||
| {{% /alert %}} | ||
|
|
||
| #### Syntax | ||
|
|
||
| ```sql | ||
| RPAD ( expression , length_expression [, pad_expression ] ) | ||
| ``` | ||
|
|
||
| #### expression | ||
|
|
||
| `expression` specifies the expression of type `string` to pad. | ||
|
|
||
| #### length_expression | ||
|
|
||
| `length_expression` specifies the length of the resulting string. The expression must be of type `integer` or `long` | ||
|
|
||
| {{% alert color="info" %}} | ||
| If `length_expression` is smaller than the length of `expression`, this function truncates it. | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Still normal truncation - so the same as LPAD?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep. |
||
| {{% /alert %}} | ||
|
|
||
| #### pad_expression | ||
|
|
||
| `pad_expression` is an optional parameter that specifies the character or string to pad with. If not specified, the space character is used. | ||
|
|
||
| #### Examples | ||
|
|
||
| ```sql | ||
| SELECT RPAD('hello', 10) AS padded FROM Sales.Order | ||
| ``` | ||
|
|
||
| | padded | | ||
| |:-----------| | ||
| | hello | | ||
|
|
||
|
|
||
| ```sql | ||
| SELECT RPAD('hello', 10, 'x') AS padded FROM Sales.Order | ||
| ``` | ||
|
|
||
| | padded | | ||
| |:-----------| | ||
| | helloxxxxx | | ||
|
|
||
| ### SUBSTRING{#substring-function} | ||
|
|
||
| #### Description | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any special behavior for
NULL? For Trim it returnsNULLbut does this just return a whole load ofpad_expression?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They just return
nullif either the expression or length are null. If the padding pattern isnull, it is usually null (HSQLDB is the exception and throws an error).And if
expressionis the empty string or the length is zero, then Oracle returns null, but other databases return the empty string.And if the padding pattern is the empty string, then Oracle and MariaDB return null, HSQLDB uses the space character, MySQL returns the empty string, and other databases return the original string. It's kind of a mess and I suppose those are cases where things can be described as "it's database dependent", so I didn't add to this page.