-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathtsarr.c
More file actions
38 lines (28 loc) · 755 Bytes
/
Copy pathtsarr.c
File metadata and controls
38 lines (28 loc) · 755 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "postgres.h"
#include "catalog/pg_type.h"
#include "tsearch/ts_type.h"
#include "utils/array.h"
PG_FUNCTION_INFO_V1(tsvector2textarray);
Datum tsvector2textarray(PG_FUNCTION_ARGS);
Datum
tsvector2textarray(PG_FUNCTION_ARGS)
{
TSVector ts = PG_GETARG_TSVECTOR(0);
ArrayType *a;
Datum *words;
int i;
WordEntry *wptr = ARRPTR(ts);
words = palloc( sizeof(Datum) * (ts->size+1) );
for(i=0; i<ts->size; i++)
{
text *t = palloc(VARHDRSZ + wptr->len);
SET_VARSIZE(t, VARHDRSZ + wptr->len);
memcpy( VARDATA(t), STRPTR(ts) + wptr->pos, wptr->len);
words[i] = PointerGetDatum(t);
wptr++;
}
a = construct_array( words, ts->size,
TEXTOID, -1, false, 'i' );
PG_FREE_IF_COPY(ts, 0);
PG_RETURN_ARRAYTYPE_P(a);
}