MCPcopy Create free account
hub / github.com/apache/cloudberry / tsvector_update_trigger

Function tsvector_update_trigger

src/backend/utils/adt/tsvector_op.c:2574–2727  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2572}
2573
2574static Datum
2575tsvector_update_trigger(PG_FUNCTION_ARGS, bool config_column)
2576{
2577 TriggerData *trigdata;
2578 Trigger *trigger;
2579 Relation rel;
2580 HeapTuple rettuple = NULL;
2581 int tsvector_attr_num,
2582 i;
2583 ParsedText prs;
2584 Datum datum;
2585 bool isnull;
2586 text *txt;
2587 Oid cfgId;
2588 bool update_needed;
2589
2590 /* Check call context */
2591 if (!CALLED_AS_TRIGGER(fcinfo)) /* internal error */
2592 elog(ERROR, "tsvector_update_trigger: not fired by trigger manager");
2593
2594 trigdata = (TriggerData *) fcinfo->context;
2595 if (!TRIGGER_FIRED_FOR_ROW(trigdata->tg_event))
2596 elog(ERROR, "tsvector_update_trigger: must be fired for row");
2597 if (!TRIGGER_FIRED_BEFORE(trigdata->tg_event))
2598 elog(ERROR, "tsvector_update_trigger: must be fired BEFORE event");
2599
2600 if (TRIGGER_FIRED_BY_INSERT(trigdata->tg_event))
2601 {
2602 rettuple = trigdata->tg_trigtuple;
2603 update_needed = true;
2604 }
2605 else if (TRIGGER_FIRED_BY_UPDATE(trigdata->tg_event))
2606 {
2607 rettuple = trigdata->tg_newtuple;
2608 update_needed = false; /* computed below */
2609 }
2610 else
2611 elog(ERROR, "tsvector_update_trigger: must be fired for INSERT or UPDATE");
2612
2613 trigger = trigdata->tg_trigger;
2614 rel = trigdata->tg_relation;
2615
2616 if (trigger->tgnargs < 3)
2617 elog(ERROR, "tsvector_update_trigger: arguments must be tsvector_field, ts_config, text_field1, ...)");
2618
2619 /* Find the target tsvector column */
2620 tsvector_attr_num = SPI_fnumber(rel->rd_att, trigger->tgargs[0]);
2621 if (tsvector_attr_num == SPI_ERROR_NOATTRIBUTE)
2622 ereport(ERROR,
2623 (errcode(ERRCODE_UNDEFINED_COLUMN),
2624 errmsg("tsvector column \"%s\" does not exist",
2625 trigger->tgargs[0])));
2626 /* This will effectively reject system columns, so no separate test: */
2627 if (!IsBinaryCoercible(SPI_gettypeid(rel->rd_att, tsvector_attr_num),
2628 TSVECTOROID))
2629 ereport(ERROR,
2630 (errcode(ERRCODE_DATATYPE_MISMATCH),
2631 errmsg("column \"%s\" is not of tsvector type",

Callers 2

Calls 15

SPI_fnumberFunction · 0.85
IsBinaryCoercibleFunction · 0.85
SPI_gettypeidFunction · 0.85
SPI_getbinvalFunction · 0.85
DatumGetObjectIdFunction · 0.85
list_lengthFunction · 0.85
get_ts_config_oidFunction · 0.85
bms_is_memberFunction · 0.85
parsetextFunction · 0.85
make_tsvectorFunction · 0.85

Tested by

no test coverage detected