mirror of
https://github.com/postgres/postgres.git
synced 2025-06-16 06:01:02 +03:00
Improve make_tsvector() to handle empty input, and simplify its callers.
It seemed a bit silly that each caller of make_tsvector() was laboriously special-casing the situation where no lexemes were found, when it would be easy and much more bullet-proof to make make_tsvector() handle that.
This commit is contained in:
@ -2579,28 +2579,15 @@ tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
|
||||
}
|
||||
|
||||
/* make tsvector value */
|
||||
if (prs.curwords)
|
||||
{
|
||||
datum = PointerGetDatum(make_tsvector(&prs));
|
||||
isnull = false;
|
||||
rettuple = heap_modify_tuple_by_cols(rettuple, rel->rd_att,
|
||||
1, &tsvector_attr_num,
|
||||
&datum, &isnull);
|
||||
pfree(DatumGetPointer(datum));
|
||||
}
|
||||
else
|
||||
{
|
||||
TSVector out = palloc(CALCDATASIZE(0, 0));
|
||||
datum = TSVectorGetDatum(make_tsvector(&prs));
|
||||
isnull = false;
|
||||
|
||||
SET_VARSIZE(out, CALCDATASIZE(0, 0));
|
||||
out->size = 0;
|
||||
datum = PointerGetDatum(out);
|
||||
isnull = false;
|
||||
rettuple = heap_modify_tuple_by_cols(rettuple, rel->rd_att,
|
||||
1, &tsvector_attr_num,
|
||||
&datum, &isnull);
|
||||
pfree(prs.words);
|
||||
}
|
||||
/* and insert it into tuple */
|
||||
rettuple = heap_modify_tuple_by_cols(rettuple, rel->rd_att,
|
||||
1, &tsvector_attr_num,
|
||||
&datum, &isnull);
|
||||
|
||||
pfree(DatumGetPointer(datum));
|
||||
|
||||
return PointerGetDatum(rettuple);
|
||||
}
|
||||
|
Reference in New Issue
Block a user