1

enter image description here

After installing PostgreSQL I keep getting an error.

"LINE 1: ...T COUNT() FROM (SELECT "blog_post"."id" AS Col1, SIMILARITY...*"

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

sudo apt install postgresql-contrib psql# CREATE EXTENSION pg_trgm; sudo service postgresql restart

(venv) dev-py@devpy-VirtualBox:~/Dev/mysite/mysite$ python manage.py runserver Watching for file changes with StatReloader Performing system checks...

System check identified no issues (0 silenced). July 12, 2019 - 20:31:19 Django version 2.2.3, using settings 'mysite.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-C. [12/Jul/2019 20:31:32] "GET /blog/search/ HTTP/1.1" 200 995 Internal Server Error: /blog/search/ Traceback (most recent call last): File "/home/dev-py/Dev/mysite/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute return self.cursor.execute(sql, params) psycopg2.errors.UndefinedFunction: function similarity(character varying, unknown) does not exist

"LINE 1: ...T COUNT() FROM (SELECT "blog_post"."id" AS Col1, SIMILARITY...*"

HINT: No function matches the given name and argument types. You might need to add explicit type casts.

Any help would be appreciated. It took me 3 days of troubleshooting this before I asked for help but I am sure someone knows the answer and it's simple. If you need any more info please just lmk.

  • 1
    1) `UndefinedFunction: function similarity(character varying, unknown) does not exist` - look at https://stackoverflow.com/a/2255053/3350428. 2) Is `COUNT()` instead of `COUNT(*)` a typo? – Andrei Odegov Jul 13 '19 at 05:58
  • Yes yes a typo. I have located the pg_trgm.control file at /usr/share/postgresql/10/extension/pg_trgm.control. But is it supposed to be in /usr/share/postgresql/10/contrib/pg_trgm ? @AndreiOdegov – RushProGlobal Jul 13 '19 at 06:30

1 Answers1

0

In order to use trigrams in PostgreSQL, you will need to install the pg_trgm extension first. Execute the following command from the shell to connect to the DB.

psql blog

Then, execute the following command to install the pg_trgm extension:

CREATE EXTENSION pg_trgm;

Done.

  • It's because (I don't know why?) TrigramSimilarity wont work on search_query. instead it will work with strings. or neither with SearchVectorField instead use regular fields. – mh-firouzjah Dec 20 '20 at 14:13