kayak / pypika

PyPika is a python SQL query builder that exposes the full richness of the SQL language using a syntax that reflects the resulting query. PyPika excels at all sorts of SQL queries but is especially useful for data analysis.
http://pypika.readthedocs.io/en/latest/
Apache License 2.0
2.43k stars 292 forks source link

Add documentation about defining custom operators #779

Open nlassaux opened 6 months ago

nlassaux commented 6 months ago

Many extensions define new operators, for example to compute various distances between geometries, vectors, etc. A useful example is <-> being used by PostGIS.

Added the documentation explaining how to leverage ArithmeticExpression to extend pypika with it, right under the explanation about how to define a custom function. Having that doc section would have saved me quite some time actually.

Thanks @wd60622 for explaining the approach!

wd60622 commented 6 months ago

Looks awesome. Thanks for making the adjustment

Only thing I would suggest is adding a brief section on this in the README like with the Custom Functions section

Any thoughts @AzisK ?

AzisK commented 6 months ago

Thanks to both of you. I don't have any additional suggestions except writing a test to be sure that people actually can define their own custom operators

wd60622 commented 6 months ago

Thanks to both of you. I don't have any additional suggestions except writing a test to be sure that people actually can define their own custom operators

Think that's fair. If someones going into the code base, I think ideally someone might be able to use a string instead of a small class.