Skip to content

fix: correct glob→lquery conversion in ltree_helpers.to_query()#65

Merged
pyramation merged 1 commit intomainfrom
fix/ltree-helpers-glob-conversion
May 5, 2026
Merged

fix: correct glob→lquery conversion in ltree_helpers.to_query()#65
pyramation merged 1 commit intomainfrom
fix/ltree-helpers-glob-conversion

Conversation

@pyramation
Copy link
Copy Markdown
Contributor

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 meant projects.* would match projects, projects.alpha, AND projects.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)
Input Before (wrong) After (correct)
/projects/* projects.* (matches all depths) projects.*{1} (matches one level)
/projects/** projects.*{1,} (1+ labels) projects.* (0+ labels)
/projects/*/docs projects.*.docs (any depth between) projects.*{1}.docs (exactly one level between)

Review & Testing Checklist for Human

  • Verify SELECT ltree_helpers.to_query('/projects/*') returns 'projects.*{1}'::lquery
  • Verify SELECT 'projects.alpha'::ltree ~ ltree_helpers.to_query('/projects/*') returns TRUE
  • Verify SELECT 'projects.alpha.docs'::ltree ~ ltree_helpers.to_query('/projects/*') returns FALSE

Notes

Same fix applied to constructive-db PR #1007 and the inline fallback in the graphile-ltree plugin (constructive PR #1056).

Link to Devin session: https://app.devin.ai/sessions/ffa3ed8652fc412f976accbdc229c88d
Requested by: @pyramation

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-integration
Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@pyramation pyramation merged commit 64fc3b1 into main May 5, 2026
24 checks passed
@pyramation pyramation deleted the fix/ltree-helpers-glob-conversion branch May 5, 2026 08:54
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.

1 participant