Add documentation for the LPAD and RPAD OQL functions#11190
Conversation
|
Awaiting 11.11 release. |
Just FYI, this still requires approval from the team and for the implementation story to be finalised. |
|
Got it, will wait for the go ahead. |
…e pad_expression multi-character alert
5bc8c1d to
a196c91
Compare
|
Approved by team for technical review |
MarkvanMents
left a comment
There was a problem hiding this comment.
Thanks for the PR. I have a few questions:
|
|
||
| #### expression | ||
|
|
||
| `expression` specifies the expression of type `string` to pad. |
There was a problem hiding this comment.
Any special behavior for NULL? For Trim it returns NULL but does this just return a whole load of pad_expression?
There was a problem hiding this comment.
They just return null if either the expression or length are null. If the padding pattern is null, it is usually null (HSQLDB is the exception and throws an error).
And if expression is 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.
There was a problem hiding this comment.
Is it worth noting that this edge case behavior depends on the database and that the customer should test them on their configuration? I'm not sure that all our users would think about this, or might raise questions about it.
| `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. |
There was a problem hiding this comment.
Truncates the right side, even though we are doing LPAD?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks for the answer. We've said that it's database specific, so let's just leave it like that, rather than trying to give an actual answer.
| ```sql | ||
| SELECT LPAD('hello', 10, 'x') AS padded FROM Sales.Order | ||
| ``` | ||
|
|
||
| | padded | | ||
| |:-----------| | ||
| | xxxxxhello | | ||
|
|
There was a problem hiding this comment.
Is it worth an example with a string pad_expression?
SELECT LPAD('hello', 10, 'abc') AS padded FROM Sales.OrderThere was a problem hiding this comment.
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?
There was a problem hiding this comment.
Let's go for the clearer one.
(I need to review this page and split it up anyhow if we want it to be translatable - another few lines won't make any difference)
| `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. |
There was a problem hiding this comment.
Still normal truncation - so the same as LPAD?
There was a problem hiding this comment.
OK - should we add the note about it being database specific to encourage the user to test it?
There was a problem hiding this comment.
RPAD is consistent. It's only LPAD that behaves differently in HSQLDB and other dbs.
| | 0.33 | 3.33333333 | | ||
| | 1.17 | 1.17142857 | | ||
|
|
||
| ### RPAD {#rpad-function} |
There was a problem hiding this comment.
Same comments as for LPAD
| | padded | | ||
| |:-----------| | ||
| | hello | |
There was a problem hiding this comment.
I suppose we can change the query to
SELECT '|' + LPAD('hello', 10) + '|' AS padded FROM Sales.Order
The resulting string would be | hello|. Would we render it correctly with spaces?
There was a problem hiding this comment.
We could also just render the result as
·····hello
Or something similar and indicate · represents a whitespace.
There was a problem hiding this comment.
Good idea. Let's do that. using the · character so it is clear we didn't mean .
MarkvanMents
left a comment
There was a problem hiding this comment.
Thanks for your answers. I've had a quick look.
Let me know if you have any questions, or would like me to draft any changes.
Mark
|
|
||
| #### expression | ||
|
|
||
| `expression` specifies the expression of type `string` to pad. |
There was a problem hiding this comment.
Is it worth noting that this edge case behavior depends on the database and that the customer should test them on their configuration? I'm not sure that all our users would think about this, or might raise questions about it.
| `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. |
There was a problem hiding this comment.
Thanks for the answer. We've said that it's database specific, so let's just leave it like that, rather than trying to give an actual answer.
| | padded | | ||
| |:-----------| | ||
| | hello | |
There was a problem hiding this comment.
Good idea. Let's do that. using the · character so it is clear we didn't mean .
| ```sql | ||
| SELECT LPAD('hello', 10, 'x') AS padded FROM Sales.Order | ||
| ``` | ||
|
|
||
| | padded | | ||
| |:-----------| | ||
| | xxxxxhello | | ||
|
|
There was a problem hiding this comment.
Let's go for the clearer one.
(I need to review this page and split it up anyhow if we want it to be translatable - another few lines won't make any difference)
| `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. |
There was a problem hiding this comment.
OK - should we add the note about it being database specific to encourage the user to test it?
7973784 to
b3249c0
Compare

Should be added in 11.11.0Changed to 11.12.0 in a196c91