Add support for PostgreSQL's trigram operators#291
Open
Niols wants to merge 1 commit into
Open
Conversation
Niols
added a commit
to Niols/sqlgg
that referenced
this pull request
Jul 4, 2026
ygrek
approved these changes
Jul 6, 2026
| } [@@deriving show] | ||
| type logical_op = And | Or | Xor [@@deriving show] | ||
| type comparison_op = Comp_equal | Comp_num_cmp | Comp_num_eq | Not_distinct_op | Is_null | Is_not_null [@@deriving eq, show] | ||
| type comparison_op = Comp_equal | Comp_num_cmp | Comp_text_cmp | Comp_num_eq | Not_distinct_op | Is_null | Is_not_null [@@deriving eq, show] |
Owner
There was a problem hiding this comment.
i was going to say i would expect some typing changes involving new ctor, but then i see there is nothing like this for comp_num_cmp either. Not for this PR but it means this is a missed opportunity to have better inference @jongleb ?
Owner
|
as for % ambiguity i think we already have some ambiguity handling but it is case by case handling, also it will be the first one to depend on dialect i think yes |
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.
Adds parsing and typing for PostgreSQL's pg_trgm operators:
<%,%>,<<%,%>>→ newTEXT_CMP_OP(comparison,Comp_text_cmp).<->,<<->,<->>,<<<->,<->>>→ newTEXT_DIST_OP(returns float).similarity,word_similarityandstrict_word_similarityfunctions (text × text → float).Note: I deliberately left out the
%trigram similarity operator. The difficulty is that%is overloaded across dialects: it's the integer moduloINT -> INT -> INTin both MySQL and PostgreSQL, but in PostgreSQL it also doubles as the trigram similarity operatorTEXT -> TEXT -> BOOL. I don't think there is currently a good way to treat such a case, but we would need to have:%sshould have type(INT -> INT -> INT) U (TEXT -> TEXT -> BOOL)).I left it as a FIXME in the lexer, and I'm willing to work on this some time if you think this is worth pursuing.