41 #define RESIZEPRSBUF \ 43 if ( state->cur - state->word + 1 >= state->wordlen ) \ 45 int32 clen = state->cur - state->word; \ 46 state->wordlen *= 2; \ 47 state->word = (char*)repalloc( (void*)state->word, state->wordlen ); \ 48 state->cur = state->word + clen; \ 56 #define GV_WAITESCIN 3 57 #define GV_WAITESCESCIN 4 72 if (*(state->
ptr) ==
'"')
77 else if (*(state->
ptr) ==
'\0')
81 else if (*(state->
ptr) ==
'=' && !ignoreeq)
83 elog(
ERROR,
"Syntax error near \"%.*s\" at position %d",
87 else if (*(state->
ptr) ==
'\\')
91 else if (!isspace((
unsigned char) *(state->
ptr)))
93 *(state->
cur) = *(state->
ptr);
100 if (*(state->
ptr) ==
'\\')
104 else if (*(state->
ptr) ==
'=' && !ignoreeq)
109 else if (*(state->
ptr) ==
',' && ignoreeq)
114 else if (isspace((
unsigned char) *(state->
ptr)))
118 else if (*(state->
ptr) ==
'\0')
126 *(state->
cur) = *(state->
ptr);
132 if (*(state->
ptr) ==
'\\')
136 else if (*(state->
ptr) ==
'"')
140 else if (*(state->
ptr) ==
'\0')
147 *(state->
cur) = *(state->
ptr);
153 if (*(state->
ptr) ==
'\0')
156 *(state->
cur) = *(state->
ptr);
162 if (*(state->
ptr) ==
'\0')
165 *(state->
cur) = *(state->
ptr);
170 elog(
ERROR,
"Unknown state %d at position line %d in file '%s'", st, __LINE__, __FILE__);
187 bool escaped =
false;
199 if (!
get_val(state,
false, &escaped))
214 if (*(state->
ptr) ==
'=')
218 else if (*(state->
ptr) ==
'\0')
222 else if (!isspace((
unsigned char) *(state->
ptr)))
224 elog(
ERROR,
"Syntax error near \"%.*s\" at position %d",
231 if (*(state->
ptr) ==
'>')
235 else if (*(state->
ptr) ==
'\0')
241 elog(
ERROR,
"Syntax error near \"%.*s\" at position %d",
248 if (!
get_val(state,
true, &escaped))
254 if (state->
cur - state->
word == 4 && !escaped)
256 state->
word[4] =
'\0';
266 if (*(state->
ptr) ==
',')
270 else if (*(state->
ptr) ==
'\0')
274 else if (!isspace((
unsigned char) *(state->
ptr)))
276 elog(
ERROR,
"Syntax error near \"%.*s\" at position %d",
282 elog(
ERROR,
"Unknown state %d at line %d in file '%s'", st, __LINE__, __FILE__);
356 memcpy(res, ptr,
sizeof(
Pairs));
371 (
errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
372 errmsg(
"string too long for hstore key")));
381 (
errcode(ERRCODE_STRING_DATA_RIGHT_TRUNCATION),
382 errmsg(
"string too long for hstore value")));
408 for (i = 0; i < pcount; i++)
458 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
459 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
463 for (i = 0; i < pcount; ++
i)
470 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
471 errmsg(
"null value not allowed for hstore key")));
567 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
568 errmsg(
"wrong number of array subscripts")));
571 TEXTOID, -1,
false, TYPALIGN_INT,
572 &key_datums, &key_nulls, &key_count);
577 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
578 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
586 value_count = key_count;
598 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
599 errmsg(
"wrong number of array subscripts")));
606 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
607 errmsg(
"arrays must have same bounds")));
610 TEXTOID, -1,
false, TYPALIGN_INT,
611 &value_datums, &value_nulls, &value_count);
613 Assert(key_count == value_count);
618 for (i = 0; i < key_count; ++
i)
622 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
623 errmsg(
"null value not allowed for hstore key")));
625 if (!value_nulls || value_nulls[i])
682 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
683 errmsg(
"array must have even number of elements")));
689 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
690 errmsg(
"array must have two columns")));
695 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
696 errmsg(
"wrong number of array subscripts")));
700 TEXTOID, -1,
false, TYPALIGN_INT,
701 &in_datums, &in_nulls, &in_count);
703 count = in_count / 2;
708 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
709 errmsg(
"number of pairs (%d) exceeds the maximum allowed (%d)",
714 for (i = 0; i < count; ++
i)
718 (
errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
719 errmsg(
"null value not allowed for hstore key")));
721 if (in_nulls[i * 2 + 1])
822 ncolumns = tupdesc->
natts;
829 if (my_extra == NULL ||
832 fcinfo->flinfo->fn_extra =
864 nulls = (
bool *)
palloc(ncolumns *
sizeof(
bool));
875 for (i = 0, j = 0; i < ncolumns; ++
i)
883 if (att->attisdropped)
889 if (!nulls || nulls[i])
955 (
errcode(ERRCODE_DATATYPE_MISMATCH),
956 errmsg(
"first argument must be a rowtype")));
1006 ncolumns = tupdesc->
natts;
1022 if (my_extra == NULL ||
1025 fcinfo->flinfo->fn_extra =
1047 nulls = (
bool *)
palloc(ncolumns *
sizeof(
bool));
1056 for (i = 0; i < ncolumns; ++
i)
1063 for (i = 0; i < ncolumns; ++
i)
1073 if (att->attisdropped)
1081 strlen(
NameStr(att->attname)));
1121 value =
palloc(1 + vallen);
1122 memcpy(value,
HSTORE_VAL(entries, ptr, idx), vallen);
1143 fcinfo->flinfo->fn_mcxt);
1152 cpw(
char *dst,
char *src,
int len)
1156 while (ptr - src < len)
1158 if (*ptr ==
'"' || *ptr ==
'\\')
1191 for (i = 0; i < count; i++)
1201 out = ptr =
palloc(buflen);
1203 for (i = 0; i < count; i++)
1251 for (i = 0; i < count; i++)
1302 for (i = 0; i < count; i++)
1357 for (i = 0; i < count; i++)
1396 for (i = 0; i < count; i++)
1442 for (i = 0; i < count; i++)
1462 val.
val.boolean =
true;
1468 val.
val.boolean =
false;
Datum hstore_in(PG_FUNCTION_ARGS)
#define PG_RETURN_POINTER(x)
Datum hstore_to_jsonb_loose(PG_FUNCTION_ARGS)
struct ColumnIOData ColumnIOData
Datum hstore_out(PG_FUNCTION_ARGS)
Datum hstore_to_jsonb(PG_FUNCTION_ARGS)
void getTypeOutputInfo(Oid type, Oid *typOutput, bool *typIsVarlena)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
Datum hstore_to_json(PG_FUNCTION_ARGS)
void escape_json(StringInfo buf, const char *str)
#define PG_GETARG_HSTORE_P(x)
#define MaxTupleAttributeNumber
#define TupleDescAttr(tupdesc, i)
char * pstrdup(const char *in)
#define HSTORE_KEYLEN(arr_, i_)
StringInfoData * StringInfo
size_t hstoreCheckValLen(size_t len)
#define FLEXIBLE_ARRAY_MEMBER
int errcode(int sqlerrcode)
#define MemSet(start, val, len)
Datum idx(PG_FUNCTION_ARGS)
#define HSTORE_VALLEN(arr_, i_)
#define PG_GETARG_POINTER(n)
Datum hstore_from_arrays(PG_FUNCTION_ARGS)
HeapTuple heap_form_tuple(TupleDesc tupleDescriptor, Datum *values, bool *isnull)
int pg_strcasecmp(const char *s1, const char *s2)
#define PG_RETURN_BYTEA_P(x)
#define PG_GETARG_HEAPTUPLEHEADER(n)
Datum hstore_from_text(PG_FUNCTION_ARGS)
Datum hstore_to_json_loose(PG_FUNCTION_ARGS)
TupleDesc lookup_rowtype_tupdesc_domain(Oid type_id, int32 typmod, bool noError)
#define PG_GETARG_TEXT_PP(n)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
#define HeapTupleHeaderGetTypMod(tup)
static char * cpw(char *dst, char *src, int len)
JsonbValue * pushJsonbValue(JsonbParseState **pstate, JsonbIteratorToken seq, JsonbValue *jbval)
#define PG_GETARG_ARRAYTYPE_P(n)
#define HSTORE_VALISNULL(arr_, i_)
void pfree(void *pointer)
static void parse_hstore(HSParser *state)
#define ObjectIdGetDatum(X)
int hstoreFindKey(HStore *hs, int *lowbound, char *key, int keylen)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
HStore * hstorePairs(Pairs *pairs, int32 pcount, int32 buflen)
void appendStringInfoString(StringInfo str, const char *s)
text * cstring_to_text_with_len(const char *s, int len)
static int comparePairs(const void *a, const void *b)
#define CStringGetDatum(X)
FormData_pg_attribute * Form_pg_attribute
void resetStringInfo(StringInfo str)
#define HS_ADDITEM(dent_, dbuf_, dptr_, pair_)
Datum numeric_in(PG_FUNCTION_ARGS)
bool type_is_rowtype(Oid typid)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
#define HSTORE_KEY(arr_, str_, i_)
HSTORE_POLLUTE(hstore_from_text, tconvert)
bool IsValidJsonNumber(const char *str, int len)
void getTypeInputInfo(Oid type, Oid *typInput, Oid *typIOParam)
#define HS_FINALIZE(hsp_, count_, buf_, ptr_)
struct RecordIOData RecordIOData
#define DirectFunctionCall3(func, arg1, arg2, arg3)
void appendStringInfoChar(StringInfo str, char ch)
void initStringInfo(StringInfo str)
#define CALCDATASIZE(x, lenstr)
ColumnIOData columns[FLEXIBLE_ARRAY_MEMBER]
#define PG_RETURN_DATUM(x)
#define HeapTupleHeaderGetTypeId(tup)
int hstoreUniquePairs(Pairs *a, int32 l, int32 *buflen)
void domain_check(Datum value, bool isnull, Oid domainType, void **extra, MemoryContext mcxt)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Datum hstore_send(PG_FUNCTION_ARGS)
Datum hstore_populate_record(PG_FUNCTION_ARGS)
#define HSTORE_MAX_KEY_LEN
#define ereport(elevel,...)
#define PG_RETURN_TEXT_P(x)
text * cstring_to_text(const char *s)
Datum hstore_from_array(PG_FUNCTION_ARGS)
#define DatumGetNumeric(X)
#define Assert(condition)
Datum hstore_from_record(PG_FUNCTION_ARGS)
#define PG_RETURN_CSTRING(x)
PG_FUNCTION_INFO_V1(hstore_in)
int pg_mblen(const char *mbstr)
#define HeapTupleGetDatum(tuple)
void * repalloc(void *pointer, Size size)
#define HSTORE_VAL(arr_, str_, i_)
void heap_deform_tuple(HeapTuple tuple, TupleDesc tupleDesc, Datum *values, bool *isnull)
void deconstruct_array(ArrayType *array, Oid elmtype, int elmlen, bool elmbyval, char elmalign, Datum **elemsp, bool **nullsp, int *nelemsp)
static Datum values[MAXATTR]
size_t hstoreCheckKeyLen(size_t len)
#define ItemPointerSetInvalid(pointer)
#define VARSIZE_ANY_EXHDR(PTR)
int errmsg(const char *fmt,...)
#define HSTORE_MAX_VALUE_LEN
void * MemoryContextAlloc(MemoryContext context, Size size)
Datum hstore_recv(PG_FUNCTION_ARGS)
#define PG_GETARG_CSTRING(n)
#define SET_VARSIZE(PTR, len)
#define HS_SETCOUNT(hsp_, c_)
#define qsort(a, b, c, d)
#define ReleaseTupleDesc(tupdesc)
static bool get_val(HSParser *state, bool ignoreeq, bool *escaped)
void appendBinaryStringInfo(StringInfo str, const char *data, int datalen)
#define offsetof(type, field)
#define HeapTupleHeaderGetDatumLength(tup)