Skip to content

feat($substrCP/$substrBytes/$substr): substring operators#8

Merged
douglasjordan2 merged 1 commit into
mainfrom
feature/substr-operators
Jun 17, 2026
Merged

feat($substrCP/$substrBytes/$substr): substring operators#8
douglasjordan2 merged 1 commit into
mainfrom
feature/substr-operators

Conversation

@douglasjordan2

Copy link
Copy Markdown
Owner

Summary

Implements the three MongoDB substring operators (#1):

  • $substrCP — substring by code points; compiles to substring(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 via convert_from(substring(convert_to(input, 'UTF8') from start + 1 for length), 'UTF8'). Note: this deviates from the issue's sketch, which cast bytea::text — that yields hex-escape form, not the decoded string.

Tests

  • 2 unit tests asserting SQL shape (1-indexed offset, bytea round-trip, parameterized values)
  • Integration test derives an excerpt from $body end-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]
  • 91 pass / 0 fail, tsc --noEmit clean

README expression list updated.

Closes #1

🤖 Generated with Claude Code

$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>
@douglasjordan2 douglasjordan2 merged commit 5abb1f5 into main Jun 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add $substr / $substrCP / $substrBytes string operators

1 participant