I'm creating an index over several text columns (in Postgres 9.3) and I would like to use concat, e.g:
CREATE INDEX
ON my_table
USING gin (to_tsvector('english', concat(title, ' ', description)))
However, when I try to do this I get the following error:
ERROR: functions in index expression must be marked IMMUTABLE
Vanilla concatenation with the || operator works fine. However, I'd prefer to use concat since description might be NULL, and the || operator seems to turn any concatenation with NULL into NULL.
If I understand this correctly this means that concat is not marked as immutable, which I don't understand.
Of course, I can just coalesce all the nullable columns, but it feels inelegant. More than anything, I'm curious as to why I can't use concat in my index?
concat_ws()which handles the NULL cases, too.coalesce()insideto_tsvector()(and thetsvectorconcatenation with||), f.ex.:to_tsvector('english',coalesce(title,'')) || to_tsvector('english',coalesce(description,''))