From 04a2c7f412d01da8100de79b13df4fd39e15ce25 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Tue, 18 Jul 2017 13:13:47 -0400 Subject: 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. --- src/backend/utils/adt/tsvector_op.c | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'src/backend/utils/adt/tsvector_op.c') diff --git a/src/backend/utils/adt/tsvector_op.c b/src/backend/utils/adt/tsvector_op.c index 2d7407c29cb..822520299ed 100644 --- a/src/backend/utils/adt/tsvector_op.c +++ b/src/backend/utils/adt/tsvector_op.c @@ -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)); - - 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); - } + datum = TSVectorGetDatum(make_tsvector(&prs)); + isnull = false; + + /* 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); } -- cgit v1.2.3