50 if ( state->cur - state->word + 1 >= state->wordlen ) \
52 int32 clen = state->cur - state->word; \
53 state->wordlen *= 2; \
54 state->word = (char*)repalloc( (void*)state->word, state->wordlen ); \
55 state->cur = state->word + clen; \
59#define PRSSYNTAXERROR return prssyntaxerror(state)
66 errmsg(
"syntax error in hstore, near \"%.*s\" at position %d",
73#define PRSEOF return prseof(state)
80 errmsg(
"syntax error in hstore: unexpected end of string")));
90#define GV_WAITESCESCIN 4
105 if (*(
state->ptr) ==
'"')
110 else if (*(
state->ptr) ==
'\0')
114 else if (*(
state->ptr) ==
'=' && !ignoreeq)
118 else if (*(
state->ptr) ==
'\\')
131 if (*(
state->ptr) ==
'\\')
135 else if (*(
state->ptr) ==
'=' && !ignoreeq)
140 else if (*(
state->ptr) ==
',' && ignoreeq)
149 else if (*(
state->ptr) ==
'\0')
163 if (*(
state->ptr) ==
'\\')
167 else if (*(
state->ptr) ==
'"')
171 else if (*(
state->ptr) ==
'\0')
184 if (*(
state->ptr) ==
'\0')
193 if (*(
state->ptr) ==
'\0')
201 elog(
ERROR,
"unrecognized get_val state: %d", st);
218 bool escaped =
false;
251 if (*(
state->ptr) ==
'=')
255 else if (*(
state->ptr) ==
'\0')
266 if (*(
state->ptr) ==
'>')
270 else if (*(
state->ptr) ==
'\0')
293 if (
state->cur -
state->word == 4 && !escaped)
295 state->word[4] =
'\0';
305 if (*(
state->ptr) ==
',')
309 else if (*(
state->ptr) ==
'\0')
319 elog(
ERROR,
"unrecognized parse_hstore state: %d", st);
365 *buflen =
a->keylen + ((
a->isnull) ? 0 :
a->vallen);
380 memcmp(ptr->
key,
res->key,
res->keylen) == 0)
390 *buflen +=
res->keylen + ((
res->isnull) ? 0 :
res->vallen);
399 *buflen +=
res->keylen + ((
res->isnull) ? 0 :
res->vallen);
408 (
errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
409 errmsg(
"string too long for hstore key")));
418 (
errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
419 errmsg(
"string too long for hstore key")));
428 (
errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
429 errmsg(
"string too long for hstore value")));
438 (
errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
439 errmsg(
"string too long for hstore value")));
465 for (
i = 0;
i < pcount;
i++)
479 Node *escontext = fcinfo->context;
485 state.escontext = escontext;
519 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
520 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
524 for (
i = 0;
i < pcount; ++
i)
531 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
532 errmsg(
"null value not allowed for hstore key")));
628 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
629 errmsg(
"wrong number of array subscripts")));
636 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
637 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
645 value_count = key_count;
657 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
658 errmsg(
"wrong number of array subscripts")));
665 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
666 errmsg(
"arrays must have same bounds")));
670 Assert(key_count == value_count);
675 for (
i = 0;
i < key_count; ++
i)
679 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
680 errmsg(
"null value not allowed for hstore key")));
682 if (!value_nulls || value_nulls[
i])
739 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
740 errmsg(
"array must have even number of elements")));
746 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
747 errmsg(
"array must have two columns")));
752 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
753 errmsg(
"wrong number of array subscripts")));
758 count = in_count / 2;
763 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
764 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
769 for (
i = 0;
i < count; ++
i)
773 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
774 errmsg(
"null value not allowed for hstore key")));
776 if (in_nulls[
i * 2 + 1])
877 ncolumns = tupdesc->
natts;
884 if (my_extra == NULL ||
887 fcinfo->flinfo->fn_extra =
919 nulls = (
bool *)
palloc(ncolumns *
sizeof(
bool));
930 for (
i = 0,
j = 0;
i < ncolumns; ++
i)
934 Oid column_type = att->atttypid;
938 if (att->attisdropped)
944 if (!nulls || nulls[
i])
1010 (
errcode(ERRCODE_DATATYPE_MISMATCH),
1011 errmsg(
"first argument must be a rowtype")));
1061 ncolumns = tupdesc->
natts;
1077 if (my_extra == NULL ||
1080 fcinfo->flinfo->fn_extra =
1102 nulls = (
bool *)
palloc(ncolumns *
sizeof(
bool));
1111 for (
i = 0;
i < ncolumns; ++
i)
1118 for (
i = 0;
i < ncolumns; ++
i)
1122 Oid column_type = att->atttypid;
1128 if (att->attisdropped)
1136 strlen(
NameStr(att->attname)));
1198 fcinfo->flinfo->fn_mcxt);
1211 while (ptr - src <
len)
1213 if (*ptr ==
'"' || *ptr ==
'\\')
1246 for (
i = 0;
i < count;
i++)
1256 out = ptr =
palloc(buflen);
1258 for (
i = 0;
i < count;
i++)
1306 for (
i = 0;
i < count;
i++)
1355 for (
i = 0;
i < count;
i++)
1407 for (
i = 0;
i < count;
i++)
1444 for (
i = 0;
i < count;
i++)
1490 for (
i = 0;
i < count;
i++)
1510 val.val.boolean =
true;
1516 val.val.boolean =
false;
Datum idx(PG_FUNCTION_ARGS)
#define PG_GETARG_ARRAYTYPE_P(n)
void deconstruct_array_builtin(ArrayType *array, Oid elmtype, Datum **elemsp, bool **nullsp, int *nelemsp)
Datum numeric_in(PG_FUNCTION_ARGS)
static Datum values[MAXATTR]
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define MemSet(start, val, len)
static void PGresult * res
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define errsave(context,...)
#define ereport(elevel,...)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_HEAPTUPLEHEADER(n)
#define PG_RETURN_TEXT_P(x)
#define PG_RETURN_DATUM(x)
#define DirectFunctionCall3(func, arg1, arg2, arg3)
#define PG_RETURN_POINTER(x)
static Datum HeapTupleGetDatum(const HeapTupleData *tuple)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, const Datum *values, const bool *isnull)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
#define CALCDATASIZE(x, lenstr)
#define HS_FINALIZE(hsp_, count_, buf_, ptr_)
#define HSTORE_KEY(arr_, str_, i_)
#define PG_GETARG_HSTORE_P(x)
#define HSTORE_MAX_KEY_LEN
#define HS_ADDITEM(dent_, dbuf_, dptr_, pair_)
#define HSTORE_VALISNULL(arr_, i_)
#define HSTORE_VALLEN(arr_, i_)
#define HSTORE_KEYLEN(arr_, i_)
PGDLLEXPORT int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
#define HS_SETCOUNT(hsp_, c_)
#define HSTORE_MAX_VALUE_LEN
#define HSTORE_VAL(arr_, str_, i_)
Datum hstore_from_record(PG_FUNCTION_ARGS)
HStore * hstorePairs(Pairs *pairs, int32 pcount, int32 buflen)
Datum hstore_send(PG_FUNCTION_ARGS)
Datum hstore_out(PG_FUNCTION_ARGS)
Datum hstore_to_json_loose(PG_FUNCTION_ARGS)
Datum hstore_from_text(PG_FUNCTION_ARGS)
static bool prssyntaxerror(HSParser *state)
static bool get_val(HSParser *state, bool ignoreeq, bool *escaped)
static bool prseof(HSParser *state)
Datum hstore_from_array(PG_FUNCTION_ARGS)
static char * cpw(char *dst, char *src, int len)
Datum hstore_from_arrays(PG_FUNCTION_ARGS)
Datum hstore_populate_record(PG_FUNCTION_ARGS)
size_t hstoreCheckValLen(size_t len)
Datum hstore_recv(PG_FUNCTION_ARGS)
static bool hstoreCheckValLength(size_t len, HSParser *state)
struct ColumnIOData ColumnIOData
size_t hstoreCheckKeyLen(size_t len)
int hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
Datum hstore_to_json(PG_FUNCTION_ARGS)
static bool parse_hstore(HSParser *state)
PG_FUNCTION_INFO_V1(hstore_in)
Datum hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
Datum hstore_in(PG_FUNCTION_ARGS)
static int comparePairs(const void *a, const void *b)
static bool hstoreCheckKeyLength(size_t len, HSParser *state)
HSTORE_POLLUTE(hstore_from_text, tconvert)
struct RecordIOData RecordIOData
Datum hstore_to_jsonb(PG_FUNCTION_ARGS)
static int32 HeapTupleHeaderGetTypMod(const HeapTupleHeaderData *tup)
#define MaxTupleAttributeNumber
static uint32 HeapTupleHeaderGetDatumLength(const HeapTupleHeaderData *tup)
static Oid HeapTupleHeaderGetTypeId(const HeapTupleHeaderData *tup)
if(TABLE==NULL||TABLE_index==NULL)
static void ItemPointerSetInvalid(ItemPointerData *pointer)
void escape_json_with_len(StringInfo buf, const char *str, int len)
bool IsValidJsonNumber(const char *str, size_t len)
JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
bool type_is_rowtype(Oid typid)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
int pg_mblen(const char *mbstr)
void * MemoryContextAlloc(MemoryContext context, Size size)
char * pstrdup(const char *in)
void * repalloc(void *pointer, Size size)
void pfree(void *pointer)
#define SOFT_ERROR_OCCURRED(escontext)
static Numeric DatumGetNumeric(Datum X)
FormData_pg_attribute * Form_pg_attribute
int pg_strcasecmp(const char *s1, const char *s2)
#define qsort(a, b, c, d)
static Datum ObjectIdGetDatum(Oid X)
static Datum CStringGetDatum(const char *X)
static Datum Int32GetDatum(int32 X)
bool scanner_isspace(char ch)
void resetStringInfo(StringInfo str)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
void appendStringInfoString(StringInfo str, const char *s)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
StringInfoData * StringInfo
ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER]
#define ReleaseTupleDesc(tupdesc)
static FormData_pg_attribute * TupleDescAttr(TupleDesc tupdesc, int i)
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
#define SET_VARSIZE(PTR, len)
#define VARSIZE_ANY_EXHDR(PTR)
text * cstring_to_text_with_len(const char *s, int len)