Ejemplo n.º 1
0
Datum
ltree_textadd(PG_FUNCTION_ARGS)
{
	ltree	   *a = PG_GETARG_LTREE(1);
	text	   *b = PG_GETARG_TEXT_P(0);
	char	   *s;
	ltree	   *r,
			   *tmp;

	s = (char *) palloc(VARSIZE(b) - VARHDRSZ + 1);
	memcpy(s, VARDATA(b), VARSIZE(b) - VARHDRSZ);
	s[VARSIZE(b) - VARHDRSZ] = '\0';

	tmp = (ltree *) DatumGetPointer(DirectFunctionCall1(
														ltree_in,
														PointerGetDatum(s)
														));

	pfree(s);

	r = ltree_concat(tmp, a);

	pfree(tmp);

	PG_FREE_IF_COPY(a, 1);
	PG_FREE_IF_COPY(b, 0);
	PG_RETURN_POINTER(r);
}
Ejemplo n.º 2
0
Datum
ltree_addltree(PG_FUNCTION_ARGS)
{
    ltree	   *a = PG_GETARG_LTREE(0);
    ltree	   *b = PG_GETARG_LTREE(1);
    ltree	   *r;

    r = ltree_concat(a, b);
    PG_FREE_IF_COPY(a, 0);
    PG_FREE_IF_COPY(b, 1);
    PG_RETURN_POINTER(r);
}
Ejemplo n.º 3
0
Datum
ltree_textadd(PG_FUNCTION_ARGS)
{
    ltree	   *a = PG_GETARG_LTREE(1);
    text	   *b = PG_GETARG_TEXT_PP(0);
    char	   *s;
    ltree	   *r,
               *tmp;

    s = text_to_cstring(b);

    tmp = (ltree *) DatumGetPointer(DirectFunctionCall1(ltree_in,
                                    PointerGetDatum(s)));

    pfree(s);

    r = ltree_concat(tmp, a);

    pfree(tmp);

    PG_FREE_IF_COPY(a, 1);
    PG_FREE_IF_COPY(b, 0);
    PG_RETURN_POINTER(r);
}