feat($substrCP/$substrBytes/$substr): substring operators#8
Merged
Conversation
$substrCP compiles to substring(input from start + 1 for length), translating Mongo's 0-indexed start to Postgres's 1-indexed. $substr is an alias of $substrCP per the deprecated-Mongo contract. $substrBytes round-trips through convert_to(input, 'UTF8') / convert_from so it slices actual bytes (a bare bytea::text cast would emit hex-escape form, not the decoded string). Tests: 2 unit (substring shape, +1 offset, bytea round-trip, params) + 1 integration deriving an excerpt from $body and proving the CP/byte distinction on a multibyte literal (substrCP "hél" vs substrBytes "hé"). README strings list updated. 91 pass / 0 fail. tsc clean. Closes #1 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Implements the three MongoDB substring operators (#1):
$substrCP— substring by code points; compiles tosubstring(input from start + 1 for length), translating Mongo's 0-indexed start to Postgres's 1-indexed$substr— deprecated-Mongo alias of$substrCP, per the issue spec$substrBytes— substring by bytes viaconvert_from(substring(convert_to(input, 'UTF8') from start + 1 for length), 'UTF8'). Note: this deviates from the issue's sketch, which castbytea::text— that yields hex-escape form, not the decoded string.Tests
$bodyend-to-end and proves the code-point vs byte distinction on a multibyte literal:$substrCP: ["héllo", 0, 3]→hél,$substrBytes: ["héllo", 0, 3]→hétsc --noEmitcleanREADME expression list updated.
Closes #1
🤖 Generated with Claude Code