39 int stopLow = lowbound ? *lowbound : 0;
44 while (stopLow < stopHigh)
48 stopMiddle = stopLow + (stopHigh - stopLow) / 2;
51 difference = memcmp(
HSTORE_KEY(entries, base, stopMiddle),
key, keylen);
53 difference = (
HSTORE_KEYLEN(entries, stopMiddle) > keylen) ? 1 : -1;
58 *lowbound = stopMiddle + 1;
61 else if (difference < 0)
62 stopLow = stopMiddle + 1;
64 stopHigh = stopMiddle;
84 TEXTOID, -1,
false, TYPALIGN_INT,
85 &key_datums, &key_nulls, &key_count);
102 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
103 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
108 for (i = 0, j = 0; i < key_count; i++)
114 key_pairs[j].
val = NULL;
180 for (i = 0; i < nkeys; i++)
183 key_pairs[i].
key, key_pairs[i].keylen);
214 for (i = 0; i < nkeys; i++)
217 key_pairs[i].
key, key_pairs[i].keylen);
268 bufd = ptrd =
STRPTR(out);
271 for (i = 0; i < count; ++
i)
276 if (!(len == keylen && memcmp(ptrs, keyptr, keylen) == 0))
333 for (i = j = 0; i < hs_count;)
343 if (skeylen == key_pairs[j].keylen)
346 key_pairs[j].keylen);
348 difference = (skeylen > key_pairs[j].
keylen) ? 1 : -1;
353 else if (difference == 0)
416 for (i = j = 0; i < hs_count;)
427 if (skeylen == s2keylen)
432 difference = (skeylen > s2keylen) ? 1 : -1;
437 else if (difference == 0)
524 for (s1idx = s2idx = 0; s1idx < s1count || s2idx < s2count; ++outcount)
528 if (s1idx >= s1count)
530 else if (s2idx >= s2count)
537 if (s1keylen == s2keylen)
538 difference = memcmp(
HSTORE_KEY(es1, ps1, s1idx),
542 difference = (s1keylen > s2keylen) ? 1 : -1;
586 TEXTOID, -1,
false, TYPALIGN_INT,
587 &key_datums, &key_nulls, &key_count);
596 out_nulls =
palloc(
sizeof(
bool) * key_count);
598 for (i = 0; i < key_count; ++
i)
611 out_datums[
i] = (
Datum) 0;
618 out_nulls[
i] =
false;
626 TEXTOID, -1,
false, TYPALIGN_INT);
666 for (i = 0; i < nkeys; ++
i)
669 key_pairs[i].
key, key_pairs[i].keylen);
673 out_pairs[out_count].
key = key_pairs[
i].
key;
674 bufsiz += (out_pairs[out_count].
keylen = key_pairs[
i].
keylen);
678 out_pairs[out_count].
needfree =
false;
714 for (i = 0; i < count; ++
i)
723 TEXTOID, -1,
false, TYPALIGN_INT);
750 nulls = (
bool *)
palloc(
sizeof(
bool) * count);
752 for (i = 0; i < count; ++
i)
770 TEXTOID, -1,
false, TYPALIGN_INT);
782 int out_size[2] = {0, 2};
790 if (count == 0 || ndims == 0)
793 out_size[0] = count * 2 / ndims;
795 out_nulls =
palloc(
sizeof(
bool) * count * 2);
797 for (i = 0; i < count; ++
i)
803 out_nulls[i * 2] =
false;
807 out_datums[i * 2 + 1] = (
Datum) 0;
808 out_nulls[i * 2 + 1] =
true;
816 out_nulls[i * 2 + 1] =
false;
822 TEXTOID, -1,
false, TYPALIGN_INT);
874 elog(
ERROR,
"return type must be a row type");
945 (funcctx)->call_cntr++;
973 char *tstr =
STRPTR(tmpl);
987 for (i = 0; res && i < tcount; ++
i)
1049 bool nulls[2] = {
false,
false};
1059 dvalues[1] = (
Datum) 0;
1095 if (hcount1 == 0 || hcount2 == 0)
1103 else if (hcount2 > 0)
1109 char *str1 =
STRPTR(hs1);
1110 char *str2 =
STRPTR(hs2);
1113 size_t len1 =
HSE_ENDPOS(ent1[2 * hcount1 - 1]);
1114 size_t len2 =
HSE_ENDPOS(ent2[2 * hcount2 - 1]);
1116 res = memcmp(str1, str2,
Min(len1, len2));
1122 else if (len1 < len2)
1124 else if (hcount1 > hcount2)
1126 else if (hcount2 > hcount1)
1130 int count = hcount1 * 2;
1133 for (i = 0; i < count; ++
i)
1152 res = (res > 0) ? 1 : -1;
#define PG_RETURN_POINTER(x)
Datum hstore_fetchval(PG_FUNCTION_ARGS)
Datum hstore_exists(PG_FUNCTION_ARGS)
Datum hstore_svals(PG_FUNCTION_ARGS)
TypeFuncClass get_call_result_type(FunctionCallInfo fcinfo, Oid *resultTypeId, TupleDesc *resultTupleDesc)
#define PG_GETARG_HSTORE_P(x)
Datum hstore_concat(PG_FUNCTION_ARGS)
#define SRF_IS_FIRSTCALL()
#define PointerGetDatum(X)
#define PG_GETARG_DATUM(n)
Datum hstore_delete_hstore(PG_FUNCTION_ARGS)
#define HSTORE_KEYLEN(arr_, i_)
Datum hstore_each(PG_FUNCTION_ARGS)
Datum hstore_contained(PG_FUNCTION_ARGS)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
#define PG_RETURN_INT32(x)
ArrayType * construct_array(Datum *elems, int nelems, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
Datum hstore_cmp(PG_FUNCTION_ARGS)
int errcode(int sqlerrcode)
Datum idx(PG_FUNCTION_ARGS)
#define HSTORE_VALLEN(arr_, i_)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
Datum hstore_lt(PG_FUNCTION_ARGS)
ArrayType * construct_empty_array(Oid elmtype)
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
#define SRF_PERCALL_SETUP()
#define PG_GETARG_TEXT_PP(n)
Datum hstore_delete_array(PG_FUNCTION_ARGS)
Datum hstore_to_array(PG_FUNCTION_ARGS)
#define SRF_RETURN_NEXT(_funcctx, _result)
#define PG_GETARG_ARRAYTYPE_P(n)
#define HSTORE_VALISNULL(arr_, i_)
Datum hstore_exists_all(PG_FUNCTION_ARGS)
Datum hstore_gt(PG_FUNCTION_ARGS)
int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
Datum hstore_hash(PG_FUNCTION_ARGS)
TupleDesc BlessTupleDesc(TupleDesc tupdesc)
static void setup_firstcall(FuncCallContext *funcctx, HStore *hs, FunctionCallInfo fcinfo)
text * cstring_to_text_with_len(const char *s, int len)
Datum hstore_defined(PG_FUNCTION_ARGS)
Datum hstore_ge(PG_FUNCTION_ARGS)
static Datum hash_any(const unsigned char *k, int keylen)
Datum hstore_ne(PG_FUNCTION_ARGS)
#define HSTORE_KEY(arr_, str_, i_)
#define HS_FINALIZE(hsp_, count_, buf_, ptr_)
Datum hstore_hash_extended(PG_FUNCTION_ARGS)
Datum hstore_exists_any(PG_FUNCTION_ARGS)
#define CALCDATASIZE(x, lenstr)
Datum hstore_avals(PG_FUNCTION_ARGS)
#define hstoreUniquePairs
Datum hstore_eq(PG_FUNCTION_ARGS)
Datum hstore_slice_to_array(PG_FUNCTION_ARGS)
#define PG_RETURN_BOOL(x)
HSTORE_POLLUTE(hstore_fetchval, fetchval)
Datum difference(PG_FUNCTION_ARGS)
#define PG_RETURN_DATUM(x)
Pairs * hstoreArrayToPairs(ArrayType *a, int *npairs)
#define ereport(elevel,...)
Datum hstore_to_matrix(PG_FUNCTION_ARGS)
#define PG_RETURN_TEXT_P(x)
#define Assert(condition)
Datum hstore_skeys(PG_FUNCTION_ARGS)
MemoryContext multi_call_memory_ctx
PG_FUNCTION_INFO_V1(hstore_fetchval)
#define PG_FREE_IF_COPY(ptr, n)
#define HeapTupleGetDatum(tuple)
#define DatumGetPointer(X)
#define HSTORE_VAL(arr_, str_, i_)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static ArrayType * hstore_to_array_internal(HStore *hs, int ndims)
Datum hstore_contains(PG_FUNCTION_ARGS)
#define VARSIZE_ANY_EXHDR(PTR)
int errmsg(const char *fmt,...)
#define HS_COPYITEM(dent_, dbuf_, dptr_, sptr_, klen_, vlen_, vnull_)
#define SET_VARSIZE(PTR, len)
Datum hstore_delete(PG_FUNCTION_ARGS)
Datum hstore_akeys(PG_FUNCTION_ARGS)
#define HS_SETCOUNT(hsp_, c_)
#define HS_FIXSIZE(hsp_, count_)
Datum hstore_le(PG_FUNCTION_ARGS)
ArrayType * construct_md_array(Datum *elems, bool *nulls, int ndims, int *dims, int *lbs, Oid elmtype, int elmlen, bool elmbyval, char elmalign)
#define PG_GETARG_INT64(n)
#define DirectFunctionCall2(func, arg1, arg2)
#define SRF_RETURN_DONE(_funcctx)
Datum hstore_slice_to_hstore(PG_FUNCTION_ARGS)
#define SRF_FIRSTCALL_INIT()