Use update value of a field in to_tsvector function

20 views Asked by At

Sorry if this is duplicate question. I didn't find anything related in suggested posts. Consider this query run on Postgres 11, why the inputs of to_tsvector function are updated values of first_name and last_name?

I was expecting to_tsvector to use old values of first_name and last_name.

UPDATE 
  "user" 
SET 
  "first_name" = 'foo foo', 
  "last_name" = 'fee fee', 
  "search_vector" = to_tsvector(
    COALESCE(
      "user"."first_name", ' '
    ) || ' ' || COALESCE(
      "user"."last_name", ' '
    )
  ) 
WHERE 
  "user"."id" = 1660
In [78]: f.search_vector
Out[78]: "'fee':3,4 'foo':1,2"
0

There are 0 answers