Skip to content

Add documentation for the LPAD and RPAD OQL functions#11190

Open
passalaqua wants to merge 3 commits into
mendix:developmentfrom
passalaqua:dat/feature/pad-functions
Open

Add documentation for the LPAD and RPAD OQL functions#11190
passalaqua wants to merge 3 commits into
mendix:developmentfrom
passalaqua:dat/feature/pad-functions

Conversation

@passalaqua
Copy link
Copy Markdown
Contributor

@passalaqua passalaqua commented May 12, 2026

Should be added in 11.11.0

Changed to 11.12.0 in a196c91

@katarzyna-koltun-mx katarzyna-koltun-mx self-assigned this May 12, 2026
@katarzyna-koltun-mx
Copy link
Copy Markdown
Collaborator

Awaiting 11.11 release.

@passalaqua
Copy link
Copy Markdown
Contributor Author

Awaiting 11.11 release.

Just FYI, this still requires approval from the team and for the implementation story to be finalised.

@katarzyna-koltun-mx
Copy link
Copy Markdown
Collaborator

Got it, will wait for the go ahead.

Comment thread content/en/docs/refguide/modeling/domain-model/oql/oql-expression-syntax.md Outdated
@passalaqua passalaqua force-pushed the dat/feature/pad-functions branch from 5bc8c1d to a196c91 Compare May 20, 2026 14:44
@pijuskri
Copy link
Copy Markdown
Contributor

Approved by team for technical review

Copy link
Copy Markdown
Collaborator

@MarkvanMents MarkvanMents left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I have a few questions:


#### expression

`expression` specifies the expression of type `string` to pad.
Copy link
Copy Markdown
Collaborator

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 returns NULL but does this just return a whole load of pad_expression?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

`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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Truncates the right side, even though we are doing LPAD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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.

Comment on lines +1377 to +1384
```sql
SELECT LPAD('hello', 10, 'x') AS padded FROM Sales.Order
```

| padded |
|:-----------|
| xxxxxhello |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth an example with a string pad_expression?

SELECT LPAD('hello', 10, 'abc') AS padded FROM Sales.Order

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

`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.
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still normal truncation - so the same as LPAD?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

| 0.33 | 3.33333333 |
| 1.17 | 1.17142857 |

### RPAD {#rpad-function}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comments as for LPAD

Comment on lines +1372 to +1374
| padded |
|:-----------|
| hello |
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks wrong when built. May have to think around this (  would work - but still difficult to see that it is space padded rather than right justified)

Image

)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also just render the result as

·····hello

Or something similar and indicate · represents a whitespace.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants