patternsqlModerate
What does the Postgres <-> operator do?
Viewed 0 times
thepostgreswhatoperatordoes
Problem
I was reading through the Postgres documentation on materialized views and in one example they use the following:
I tried to run a similar query on my own database, but I get an error.
I (probably) don't need to use the operator, but I'm just curious what it does.
Notes:
SELECT word FROM words ORDER BY word 'caterpiler' LIMIT 10;I tried to run a similar query on my own database, but I get an error.
[42883] ERROR: operator does not exist: character varying unknownI (probably) don't need to use the operator, but I'm just curious what it does.
Notes:
- I am running the same version as the docs (9.3)
- I did try Googling the question, but Google just ignores the `` even if you wrap it in quotes.
Solution
It's supposed to be the "distance" operator from the additional module pg_trgm.
The manual:
The module has to be installed (once per database) with:
More details:
Theoretically, any user with the necessary privileges could create an operator with that operator name using
The manual:
text text → real Returns the "distance" between the arguments, that is one minus the similarity() value.The module has to be installed (once per database) with:
CREATE EXTENSION pg_trgm;More details:
- How is LIKE implemented?
Theoretically, any user with the necessary privileges could create an operator with that operator name using
CREATE OPERATOR - but not in the example you link to.Code Snippets
CREATE EXTENSION pg_trgm;Context
StackExchange Database Administrators Q#86773, answer score: 18
Revisions (0)
No revisions yet.