Skip to content

Solving ‘function “lexize” already exists with same argument types’ in PostgreSQL

If you run across:

function "lexize" already exists with same argument types

in PostgreSQL, when adding tsearch2 to a database, even when you’ve created a fresh new database, you probably have a corrupt copy of tsearch2 in your template1 database, which is used to create your ‘fresh’ database.

To fix this, copy the uninstall_tsearch2.sql somewhere temporarily (on a Fedora-derived OS it’s at: /usr/share/pgsql/contrib/uninstall_tsearch2.sql) and remove the BEGIN; and END; transaction statements from the file, then run it against your template1, ala:

psql template1 < /tmp/uninstall_tsearch2_notransaction.sql

and it will go through and delete all of tsearch2. Expect some failure messages if it’s partially deleted already, this is normal.

Now you can load tsearch2 into your new database without complaints.