diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/hex.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/hex.md index e3283d606f212..19363255a2829 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/hex.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/hex.md @@ -101,4 +101,52 @@ SELECT HEX(0), HEX(''); +--------+--------+ | 0 | | +--------+--------+ +``` + +6. Whitespace characters (each byte → two hex digits) +```sql +SELECT HEX(' '), HEX('\t'), HEX('\n'); +``` +```text ++----------+-----------+-----------+ +| HEX(' ') | HEX('\t') | HEX('\n') | ++----------+-----------+-----------+ +| 20 | 09 | 0A | ++----------+-----------+-----------+ +``` + +7. UTF-8 multi-byte strings +```sql +SELECT HEX('ṭṛì'), HEX('ḍḍumai'); +``` +```text ++------------------+----------------------+ +| HEX('ṭṛì') | HEX('ḍḍumai') | ++------------------+----------------------+ +| E1B9ADE1B99BC3AC | E1B88DE1B88D756D6169 | ++------------------+----------------------+ +``` + +8. Negative integers (64-bit two's complement) +```sql +SELECT HEX(-128), HEX(-32768); +``` +```text ++------------------+------------------+ +| HEX(-128) | HEX(-32768) | ++------------------+------------------+ +| FFFFFFFFFFFFFF80 | FFFFFFFFFFFF8000 | ++------------------+------------------+ +``` + +9. Mixed alphanumeric strings +```sql +SELECT HEX('A1'), HEX('Hello!'); +``` +```text ++-----------+---------------+ +| HEX('A1') | HEX('Hello!') | ++-----------+---------------+ +| 4131 | 48656C6C6F21 | ++-----------+---------------+ ``` \ No newline at end of file diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md index 53c287be053c7..76d261777008f 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/initcap.md @@ -87,4 +87,76 @@ SELECT INITCAP('hello hello.,HELLO123HELlo'); +---------------------------------------+ | Hello Hello.,Hello123hello | +---------------------------------------+ +``` + +5. Empty string +```sql +SELECT INITCAP(''); +``` +```text ++-------------+ +| INITCAP('') | ++-------------+ +| | ++-------------+ +``` + +6. Multiple non-alphanumeric separators +```sql +SELECT INITCAP('word1@word2#word3$word4'); +``` +```text ++------------------------------------+ +| INITCAP('word1@word2#word3$word4') | ++------------------------------------+ +| Word1@Word2#Word3$Word4 | ++------------------------------------+ +``` + +7. UTF-8 multi-byte words +```sql +SELECT INITCAP('ṭṛì ḍḍumai hello'); +``` +```text ++--------------------------------------+ +| INITCAP('ṭṛì ḍḍumai hello') | ++--------------------------------------+ +| Ṭṛì Ḍḍumai Hello | ++--------------------------------------+ +``` + +8. Common name capitalization +```sql +SELECT INITCAP('john doe'), INITCAP('MARY JANE'); +``` +```text ++---------------------+----------------------+ +| INITCAP('john doe') | INITCAP('MARY JANE') | ++---------------------+----------------------+ +| John Doe | Mary Jane | ++---------------------+----------------------+ +``` + +9. Sentences with mixed casing +```sql +SELECT INITCAP('the quick brown fox'), INITCAP('DATABASE management SYSTEM'); +``` +```text ++--------------------------------+---------------------------------------+ +| INITCAP('the quick brown fox') | INITCAP('DATABASE management SYSTEM') | ++--------------------------------+---------------------------------------+ +| The Quick Brown Fox | Database Management System | ++--------------------------------+---------------------------------------+ +``` + +10. Multiple spaces and adjacent punctuation +```sql +SELECT INITCAP('word1 word2--word3'), INITCAP('hello, world! how are you?'); +``` +```text ++---------------------------------+---------------------------------------+ +| INITCAP('word1 word2--word3') | INITCAP('hello, world! how are you?') | ++---------------------------------+---------------------------------------+ +| Word1 Word2--Word3 | Hello, World! How Are You? | ++---------------------------------+---------------------------------------+ ``` \ No newline at end of file diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md index 2dd9518adead9..0476b8eedb495 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/lcase.md @@ -74,3 +74,51 @@ SELECT LOWER(NULL), LCASE(NULL); | NULL | NULL | +-------------+-------------+ ``` + +4. Empty string +```sql +SELECT LOWER(''), LCASE(''); +``` +```text ++-----------+-----------+ +| LOWER('') | LCASE('') | ++-----------+-----------+ +| | | ++-----------+-----------+ +``` + +5. String already lowercase or numeric-only +```sql +SELECT LOWER('already lowercase'), LCASE('abc123'); +``` +```text ++----------------------------+-----------------+ +| LOWER('already lowercase') | LCASE('abc123') | ++----------------------------+-----------------+ +| already lowercase | abc123 | ++----------------------------+-----------------+ +``` + +6. Non-alphabetic characters are passed through unchanged +```sql +SELECT LOWER('123!@#$%'), LCASE('PRICE: $99.99'); +``` +```text ++-------------------+------------------------+ +| LOWER('123!@#$%') | LCASE('PRICE: $99.99') | ++-------------------+------------------------+ +| 123!@#$% | price: $99.99 | ++-------------------+------------------------+ +``` + +7. UTF-8 multi-byte case folding +```sql +SELECT LOWER('ṬṚÌ TEST'), LCASE('ḌḌUMAI HELLO'); +``` +```text ++------------------------+---------------------------+ +| LOWER('ṬṚÌ TEST') | LCASE('ḌḌUMAI HELLO') | ++------------------------+---------------------------+ +| ṭṛì test | ḍḍumai hello | ++------------------------+---------------------------+ +``` diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md index 82427d7b6ba9d..1ef4b0a441ba9 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/ltrim.md @@ -76,3 +76,75 @@ SELECT LTRIM(NULL), LTRIM('test', NULL); | NULL | NULL | +-------------+---------------------+ ``` + +4. Empty inputs +```sql +SELECT LTRIM(''), LTRIM('test', ''); +``` +```text ++-----------+-------------------+ +| LTRIM('') | LTRIM('test', '') | ++-----------+-------------------+ +| | test | ++-----------+-------------------+ +``` + +5. Strip a multi-character prefix +```sql +SELECT LTRIM('abcdefg', 'abc'), LTRIM('123456', '12'); +``` +```text ++-------------------------+-----------------------+ +| LTRIM('abcdefg', 'abc') | LTRIM('123456', '12') | ++-------------------------+-----------------------+ +| defg | 3456 | ++-------------------------+-----------------------+ +``` + +6. Entire string matches the trim chars +```sql +SELECT LTRIM('aaaaa', 'a'), LTRIM(' ', ' '); +``` +```text ++---------------------+-------------------+ +| LTRIM('aaaaa', 'a') | LTRIM(' ', ' ') | ++---------------------+-------------------+ +| | | ++---------------------+-------------------+ +``` + +7. UTF-8 substring strip (the second arg is matched as a literal substring, not a character set) +```sql +SELECT LTRIM('ṭṛìṭṛì test', 'ṭṛì'), LTRIM('ḍḍuḍḍu hello', 'ḍu'); +``` +```text ++--------------------------------------------+---------------------------------------+ +| LTRIM('ṭṛìṭṛì test', 'ṭṛì') | LTRIM('ḍḍuḍḍu hello', 'ḍu') | ++--------------------------------------------+---------------------------------------+ +| test | ḍḍuḍḍu hello | ++--------------------------------------------+---------------------------------------+ +``` + +8. Strip a numeric prefix +```sql +SELECT LTRIM('000123', '0'), LTRIM('123abc123', '123'); +``` +```text ++----------------------+---------------------------+ +| LTRIM('000123', '0') | LTRIM('123abc123', '123') | ++----------------------+---------------------------+ +| 123 | abc123 | ++----------------------+---------------------------+ +``` + +9. Strip a punctuation prefix +```sql +SELECT LTRIM('---text---', '-'), LTRIM('@@hello@@', '@'); +``` +```text ++--------------------------+-------------------------+ +| LTRIM('---text---', '-') | LTRIM('@@hello@@', '@') | ++--------------------------+-------------------------+ +| text--- | hello@@ | ++--------------------------+-------------------------+ +``` diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/replace.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/replace.md index 48768367c312d..0b6797cc91f31 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/replace.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/replace.md @@ -105,3 +105,51 @@ SELECT REPLACE('ṭṛì ḍḍumai test ṭṛì ḍḍumannàri', 'ṭṛì', | replaced ḍḍumai test replaced ḍḍumannàri | +-----------------------------------------------------------+ ``` + +6. Empty-string edge cases — empty `str` returns empty; empty `old` returns `str` unchanged; empty `new` deletes every match +```sql +SELECT REPLACE('', 'old', 'new'), REPLACE('test', '', 'new'), REPLACE('test', 'old', ''); +``` +```text ++---------------------------+----------------------------+----------------------------+ +| REPLACE('', 'old', 'new') | REPLACE('test', '', 'new') | REPLACE('test', 'old', '') | ++---------------------------+----------------------------+----------------------------+ +| | test | test | ++---------------------------+----------------------------+----------------------------+ +``` + +7. Replacement is case-sensitive (only lowercase `hello` matches) +```sql +SELECT REPLACE('Hello HELLO hello', 'hello', 'hi'); +``` +```text ++---------------------------------------------+ +| REPLACE('Hello HELLO hello', 'hello', 'hi') | ++---------------------------------------------+ +| Hello HELLO hi | ++---------------------------------------------+ +``` + +8. `old` not present — returns `str` unchanged +```sql +SELECT REPLACE('hello world', 'xyz', 'abc'); +``` +```text ++--------------------------------------+ +| REPLACE('hello world', 'xyz', 'abc') | ++--------------------------------------+ +| hello world | ++--------------------------------------+ +``` + +9. Overlap-free repeated match +```sql +SELECT REPLACE('123123123', '123', 'ABC'); +``` +```text ++------------------------------------+ +| REPLACE('123123123', '123', 'ABC') | ++------------------------------------+ +| ABCABCABC | ++------------------------------------+ +``` diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md index 9928650e59380..4e909a2c9b0fa 100644 --- a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/string-functions/xpath-string.md @@ -83,7 +83,7 @@ SELECT xpath_string('12', '/a/b[2]'); +----------------------------------------------------+ ``` -5. Handling CDATA and comments +5. NULL input ```sql SELECT xpath_string(NULL, '/a'); ``` @@ -95,6 +95,48 @@ SELECT xpath_string(NULL, '/a'); +--------------------------+ ``` +6. CDATA sections — the CDATA payload is returned as plain text +```sql +SELECT xpath_string('', '/a'); +``` +```text ++----------------------------------------------+ +| xpath_string('', '/a') | ++----------------------------------------------+ +| 123 | ++----------------------------------------------+ +``` + +7. XML comments are skipped +```sql +SELECT xpath_string('123', '/a'); +``` +```text ++--------------------------------------------------+ +| xpath_string('123', '/a') | ++--------------------------------------------------+ +| 123 | ++--------------------------------------------------+ +``` + +8. Path does not match any node — returns empty string +```sql +SELECT xpath_string('123', '/b'); +``` +```text ++----------------------------------+ +| xpath_string('123', '/b') | ++----------------------------------+ +| | ++----------------------------------+ +``` + +9. Malformed XML — function raises an error +```sql +SELECT xpath_string('123/a>', '/a'); +ERROR 1105 (HY000): errCode = 2, detailMessage = [INVALID_ARGUMENT]Function xpath_string failed to parse XML string: Start-end tags mismatch +``` + ### Keywords XPATH_STRING, XPATH, XML