0

All of the examples in Postgres full text search documentation show creating an index by concatenating 2 columns, but I cannot solve how to do this with 3+ columns. Example from the Postgres docs:

to_tsvector(title || ' ' || body)

If I for example have another column that should be searched through called description, it seems that this syntax does not work as I expect:

to_tsvector(title || ' ' || body || ' ' || description)

It results in an index like this when I try it:

to_tsvector('english'::regconfig, ((("CompanyName" || ' '::text) || "Title") || ' '::text) || "Description")

There seems to be an extra set of parantheses wrapping the CompanyName and Title block.

Any ideas on what the syntax should be here? I'm having trouble finding any relevant documentation on using more columns with to_tsvector.

1

1 Answer 1

2

Your index is quite good and will be used whenever you use the same expression in a query.

Indexed expressions are not stored as text, but as a parsed tree structure. That way it doesn't break the index if you for example rename a used column.

The string concatenation operator || is left associative, so the parenthesized expression is identical to the one you originally wrote (with the exception of the configuration english that is required to make the expression IMMUTABLE, but I guess you just forgot that).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.