aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/tsvector_op.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2017-07-18 13:13:47 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2017-07-18 13:13:47 -0400
commit04a2c7f412d01da8100de79b13df4fd39e15ce25 (patch)
treef7fc7f0afa4fa247016962adc75bd442e158ef0d /src/backend/utils/adt/tsvector_op.c
parentb4c6d31c0be0f5c42a75d50afcf13bdd392db4a1 (diff)
downloadpostgresql-04a2c7f412d01da8100de79b13df4fd39e15ce25.tar.gz
postgresql-04a2c7f412d01da8100de79b13df4fd39e15ce25.zip
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.
Diffstat (limited to 'src/backend/utils/adt/tsvector_op.c')
-rw-r--r--src/backend/utils/adt/tsvector_op.c31
1 files changed, 9 insertions, 22 deletions
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);
}