Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create text search configuration if not exists on PostgreSQL?

Tags:

postgresql

How to create text search configuration but only when it doesn't exists? For instance, like the other create statements:

CREATE TEXT SEARCH CONFIGURATION IF NOT EXISTS text_without_accent (COPY = simple);
like image 341
Rafael Biz Avatar asked May 13 '19 14:05

Rafael Biz


People also ask

How do I use full-text search in PostgreSQL?

When performing a full-text searches on a PostgreSQL database, you must implement the to_tsvector() and to_tsquery() functions together with a match operator @@. The match operator returns a boolean value (either t or f) when you run a keyword search (tsquery) against a tsvector document.

What is FTS configuration in PostgreSQL?

A FTS configuration specifies all of the equipment necessary to transform a document into a tsvector: the parser that breaks its text into tokens, and the dictionaries, which then transform each token into a lexeme. Every call to to_tsvector() , to_tsquery() uses a configuration to perform its processing.

Is PostgreSQL good for full-text search?

Yes, You Can Keep Full-Text Search in Postgres You can get even deeper and make your Postgres full-text search even more robust, by implementing features such as highlighting results, or writing your own custom dictionaries or functions.

What is Tsvector in PostgreSQL?

tsvector. A tsvector value is a sorted list of distinct lexemes, which are words that have been normalized to merge different variants of the same word (see Chapter 12 for details).


1 Answers

Use a DO statement and capture errors:

DO
$$BEGIN
   CREATE TEXT SEARCH CONFIGURATION ...
EXCEPTION
   WHEN unique_violation THEN
      NULL;  -- ignore error
END;$$;
like image 195
Laurenz Albe Avatar answered Oct 10 '22 10:10

Laurenz Albe