Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for custom Postgres operators to be added #53324

Merged
merged 2 commits into from
Oct 29, 2024

Conversation

boris-glumpler
Copy link
Contributor

In Postgres custom operators can be defined. Currently there is no way, tho, to add these to the grammar. This PR addresses this issue.

For my particular use-case, I am maintaining a package that integrates the pg_search extension by ParadeDB into Laravel. This extension comes with a custom @@@ operator that allows for full-text search. Up until recently, using this operator had some drawbacks and there was another way to integrate the extension, which I initially used for my integration. The use of this operator has been greatly improved in the latest version, tho, and the alternative way has therefore been deprecated.

I have added a static PostgresGrammar::customOperators() method that can be called in service providers to add any needed operators. I looked into adding this to some of the other grammars as well, but couldn't find much information, tbh, so I asked @tpetry about this and apparently Postgres is the only database that allows custom operators.

@boris-glumpler
Copy link
Contributor Author

pgvector would be another example of a popular extension that adds custom operators that are not in the default set of operators. In this case these would be:

  • <-> - L2 distance
  • <#> - (negative) inner product
  • <=> - cosine distance
  • <+> - L1 distance
  • <~> - Hamming distance
  • <%> - Jaccard distance

@taylorotwell taylorotwell merged commit 029e993 into laravel:11.x Oct 29, 2024
24 checks passed
@boris-glumpler
Copy link
Contributor Author

Thanks Taylor!

@boris-glumpler boris-glumpler deleted the postgres-custom-operators branch October 29, 2024 14:08
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.

2 participants