fix: correct glob→lquery conversion in ltree_helpers.to_query()#65
Merged
pyramation merged 1 commit intomainfrom May 5, 2026
Merged
fix: correct glob→lquery conversion in ltree_helpers.to_query()#65pyramation merged 1 commit intomainfrom
pyramation merged 1 commit intomainfrom
Conversation
PostgreSQL lquery bare * matches 0+ labels (not single level).
Fix: * → *{1} (exactly one label), ** → * (0+ labels via placeholder).
This gives standard glob semantics where * = single level, ** = recursive.
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Fixes the
ltree_helpers.to_query()function to correctly convert glob-style wildcards to lquery patterns.Bug: PostgreSQL's lquery
*means "0 or more labels", not "exactly one label". The original implementation left*as-is after converting**→*{1,}, which meantprojects.*would matchprojects,projects.alpha, ANDprojects.alpha.docs— all descendants, not just direct children.Fix: Uses a placeholder technique to correctly convert:
*→*{1}(exactly one label — single-level wildcard)**→*(zero or more labels — recursive descent)/projects/*projects.*(matches all depths)projects.*{1}(matches one level)/projects/**projects.*{1,}(1+ labels)projects.*(0+ labels)/projects/*/docsprojects.*.docs(any depth between)projects.*{1}.docs(exactly one level between)Review & Testing Checklist for Human
SELECT ltree_helpers.to_query('/projects/*')returns'projects.*{1}'::lquerySELECT 'projects.alpha'::ltree ~ ltree_helpers.to_query('/projects/*')returns TRUESELECT 'projects.alpha.docs'::ltree ~ ltree_helpers.to_query('/projects/*')returns FALSENotes
Same fix applied to
constructive-dbPR #1007 and the inline fallback in thegraphile-ltreeplugin (constructive PR #1056).Link to Devin session: https://app.devin.ai/sessions/ffa3ed8652fc412f976accbdc229c88d
Requested by: @pyramation