-
Notifications
You must be signed in to change notification settings - Fork 207
Fix Oracle SUBSTR edge-case semantics #1852
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
Open
tju-yxq
wants to merge
1
commit into
IvorySQL:master
Choose a base branch
from
tju-yxq:codex/fix-oracle-substr-semantics
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| -- | ||
| -- Oracle-compatible SUBSTR character semantics | ||
| -- | ||
| SET ivorysql.compatible_mode = oracle; | ||
| SELECT substr('abcdef', 2, 2) AS normal_positive; | ||
| normal_positive | ||
| ----------------- | ||
| bc | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', 0, 2) AS zero_position; | ||
| zero_position | ||
| --------------- | ||
| ab | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', -2, 2) AS negative_position; | ||
| negative_position | ||
| ------------------- | ||
| ef | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', -2) AS negative_without_length; | ||
| negative_without_length | ||
| ------------------------- | ||
| ef | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', 2, 0) IS NULL AS zero_length_is_null; | ||
| zero_length_is_null | ||
| --------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', 2, -1) IS NULL AS negative_length_is_null; | ||
| negative_length_is_null | ||
| ------------------------- | ||
| t | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', 20) IS NULL AS past_end_is_null; | ||
| past_end_is_null | ||
| ------------------ | ||
| t | ||
| (1 row) | ||
|
|
||
| -- Positions count characters rather than bytes. | ||
| SELECT substr('你好吗', -2, 1) AS multibyte_negative; | ||
| multibyte_negative | ||
| -------------------- | ||
| 好 | ||
| (1 row) | ||
|
|
||
| SELECT substr('你好吗', 0, 2) AS multibyte_zero; | ||
| multibyte_zero | ||
| ---------------- | ||
| 你好 | ||
| (1 row) | ||
|
|
||
| -- Numeric positions and lengths retain the existing Oracle coercion path. | ||
| SELECT substr('abcdef', 2.4::number, 2.4::number) AS numeric_arguments; | ||
| numeric_arguments | ||
| ------------------- | ||
| bc | ||
| (1 row) | ||
|
|
||
| -- The byte-semantic variant remains unchanged. | ||
| SELECT substrb('abcdef', -2, 2) AS substrb_control; | ||
| substrb_control | ||
| ----------------- | ||
| ef | ||
| (1 row) | ||
|
|
||
| -- PostgreSQL mode must continue using pg_catalog.substr semantics. | ||
| SET ivorysql.compatible_mode = pg; | ||
| SELECT substr('abcdef', 0, 2) AS pg_zero_position; | ||
| pg_zero_position | ||
| ------------------ | ||
| a | ||
| (1 row) | ||
|
|
||
| SELECT substr('abcdef', 2, 0) IS NULL AS pg_zero_length_is_null; | ||
| pg_zero_length_is_null | ||
| ------------------------ | ||
| f | ||
| (1 row) | ||
|
|
||
| RESET ivorysql.compatible_mode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| -- | ||
| -- Oracle-compatible SUBSTR character semantics | ||
| -- | ||
|
|
||
| SET ivorysql.compatible_mode = oracle; | ||
|
|
||
| SELECT substr('abcdef', 2, 2) AS normal_positive; | ||
| SELECT substr('abcdef', 0, 2) AS zero_position; | ||
| SELECT substr('abcdef', -2, 2) AS negative_position; | ||
| SELECT substr('abcdef', -2) AS negative_without_length; | ||
| SELECT substr('abcdef', 2, 0) IS NULL AS zero_length_is_null; | ||
| SELECT substr('abcdef', 2, -1) IS NULL AS negative_length_is_null; | ||
| SELECT substr('abcdef', 20) IS NULL AS past_end_is_null; | ||
|
|
||
| -- Positions count characters rather than bytes. | ||
| SELECT substr('你好吗', -2, 1) AS multibyte_negative; | ||
| SELECT substr('你好吗', 0, 2) AS multibyte_zero; | ||
|
|
||
| -- Numeric positions and lengths retain the existing Oracle coercion path. | ||
| SELECT substr('abcdef', 2.4::number, 2.4::number) AS numeric_arguments; | ||
|
|
||
| -- The byte-semantic variant remains unchanged. | ||
| SELECT substrb('abcdef', -2, 2) AS substrb_control; | ||
|
|
||
| -- PostgreSQL mode must continue using pg_catalog.substr semantics. | ||
| SET ivorysql.compatible_mode = pg; | ||
| SELECT substr('abcdef', 0, 2) AS pg_zero_position; | ||
| SELECT substr('abcdef', 2, 0) IS NULL AS pg_zero_length_is_null; | ||
|
|
||
| RESET ivorysql.compatible_mode; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Return an empty result when a negative start precedes the string.
For
substr('abcdef', -7),firstis0. Line 1040 changes it to1, so the function returnsabcdefinstead ofNULL. Only an input position of zero maps to one. A negative offset before the first character must returnNULL. (download.oracle.com)Return an empty result when
first < 1. The existing wrappers will convert it toNULL. Add regression cases for both length forms and updatecontrib/ivorysql_ora/expected/ora_substr_semantics.out.Proposed fix
As per path instructions,
**/sql/*.sqlmust “Ensure comprehensive coverage of features.”🤖 Prompt for AI Agents
Source: Path instructions