60 static bool range_parse(
const char *
string,
char *flags,
char **lbound_str,
61 char **ubound_str,
Node *escontext);
63 char **bound_str,
bool *infinite,
65 static char *
range_deparse(
char flags,
const char *lbound_str,
66 const char *ubound_str);
86 Node *escontext = fcinfo->context;
100 if (!
range_parse(input_str, &flags, &lbound_str, &ubound_str, escontext))
107 escontext, &
lower.val))
112 escontext, &
upper.val))
136 char *lbound_str = NULL;
137 char *ubound_str = NULL;
282 char *bound_data =
VARDATA(bound);
293 char *bound_data =
VARDATA(bound);
326 elog(
ERROR,
"type %u is not a range type", rngtypid);
343 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
344 errmsg(
"no binary input function available for type %s",
348 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
349 errmsg(
"no binary output function available for type %s",
384 lower.inclusive =
true;
389 upper.inclusive =
false;
414 (
errcode(ERRCODE_DATA_EXCEPTION),
415 errmsg(
"range constructor flags argument must not be null")));
452 if (empty ||
lower.infinite)
473 if (empty ||
upper.infinite)
582 if (empty1 && empty2)
584 if (empty1 != empty2)
674 if (empty1 || empty2)
712 if (empty1 || empty2)
779 boundB.
lower =
false;
780 r =
make_range(typcache, &boundA, &boundB,
false, NULL);
808 if (empty1 || empty2)
851 if (empty1 || empty2)
897 if (empty1 || empty2)
938 if (empty1 || empty2)
1003 if (empty1 || empty2)
1011 if (cmp_l1l2 < 0 && cmp_u1u2 > 0)
1013 (
errcode(ERRCODE_DATA_EXCEPTION),
1014 errmsg(
"result of range difference would not be contiguous")));
1016 if (cmp_l1u2 > 0 || cmp_u1l2 < 0)
1019 if (cmp_l1l2 >= 0 && cmp_u1u2 <= 0)
1022 if (cmp_l1l2 <= 0 && cmp_u1l2 >= 0 && cmp_u1u2 <= 0)
1025 lower2.
lower =
false;
1026 return make_range(typcache, &lower1, &lower2,
false, NULL);
1029 if (cmp_l1l2 >= 0 && cmp_u1u2 >= 0 && cmp_l1u2 <= 0)
1032 upper2.
lower =
true;
1033 return make_range(typcache, &upper2, &upper1,
false, NULL);
1036 elog(
ERROR,
"unexpected case in range_minus");
1059 elog(
ERROR,
"range types do not match");
1074 (
errcode(ERRCODE_DATA_EXCEPTION),
1075 errmsg(
"result of range union would not be contiguous")));
1078 result_lower = &lower1;
1080 result_lower = &lower2;
1083 result_upper = &upper1;
1085 result_upper = &upper2;
1087 return make_range(typcache, result_lower, result_upper,
false, NULL);
1128 elog(
ERROR,
"range types do not match");
1154 result_lower = &lower1;
1156 result_lower = &lower2;
1159 result_upper = &upper1;
1161 result_upper = &upper2;
1163 return make_range(typcache, result_lower, result_upper,
false, NULL);
1197 lower2.
lower =
false;
1199 upper2.
lower =
true;
1201 *output1 =
make_range(typcache, &lower1, &lower2,
false, NULL);
1202 *output2 =
make_range(typcache, &upper2, &upper1,
false, NULL);
1221 elog(
ERROR,
"range_intersect_agg_transfn called in non-aggregate context");
1225 elog(
ERROR,
"range_intersect_agg must be called with a range");
1259 elog(
ERROR,
"range types do not match");
1267 if (empty1 && empty2)
1353 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1354 errmsg(
"could not identify a hash function for type %s",
1377 result ^= lower_hash;
1379 result ^= upper_hash;
1417 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1418 errmsg(
"could not identify a hash function for type %s",
1441 result ^= lower_hash;
1443 result ^= upper_hash;
1460 Node *escontext = fcinfo->context;
1480 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1481 errmsg(
"integer out of range")));
1483 lower.inclusive =
true;
1493 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1494 errmsg(
"integer out of range")));
1496 upper.inclusive =
false;
1507 Node *escontext = fcinfo->context;
1527 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1528 errmsg(
"bigint out of range")));
1530 lower.inclusive =
true;
1540 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1541 errmsg(
"bigint out of range")));
1543 upper.inclusive =
false;
1554 Node *escontext = fcinfo->context;
1576 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1577 errmsg(
"date out of range")));
1579 lower.inclusive =
true;
1591 (
errcode(ERRCODE_DATETIME_VALUE_OUT_OF_RANGE),
1592 errmsg(
"date out of range")));
1594 upper.inclusive =
false;
1700 if (typcache == NULL ||
1701 typcache->
type_id != rngtypid)
1705 elog(
ERROR,
"type %u is not a range type", rngtypid);
1721 bool empty,
struct Node *escontext)
1749 (
errcode(ERRCODE_DATA_EXCEPTION),
1750 errmsg(
"range lower bound must be less than or equal to range upper bound")));
1758 if (
lower->infinite)
1760 else if (
lower->inclusive)
1762 if (
upper->infinite)
1764 else if (
upper->inclusive)
1795 typlen, typstorage);
1805 typlen, typstorage);
1809 msize +=
sizeof(char);
1818 ptr = (
char *) (
range + 1);
1834 *((
char *) ptr) = flags;
1878 lbound =
fetch_att(ptr, typbyval, typlen);
1888 ubound =
fetch_att(ptr, typbyval, typlen);
1898 lower->val = lbound;
1901 lower->lower =
true;
1903 upper->val = ubound;
1906 upper->lower =
false;
1946 bool empty,
struct Node *escontext)
1967 fcinfo->args[0].isnull =
false;
1976 elog(
ERROR,
"function %u returned NULL",
2026 return b1->
lower ? -1 : 1;
2029 return b1->
lower ? -1 : 1;
2031 return b2->
lower ? 1 : -1;
2053 return b1->
lower ? 1 : -1;
2056 return b1->
lower ? 1 : -1;
2058 return b2->
lower ? -1 : 1;
2099 return b1->
lower ? -1 : 1;
2102 return b1->
lower ? -1 : 1;
2104 return b2->
lower ? 1 : -1;
2138 if (empty1 && empty2)
2164 lower.infinite =
false;
2165 lower.inclusive =
false;
2169 upper.infinite =
false;
2170 upper.inclusive =
false;
2171 upper.lower =
false;
2192 if (flags_str[0] ==
'\0' ||
2193 flags_str[1] ==
'\0' ||
2194 flags_str[2] !=
'\0')
2196 (
errcode(ERRCODE_SYNTAX_ERROR),
2197 errmsg(
"invalid range bound flags"),
2198 errhint(
"Valid values are \"[]\", \"[)\", \"(]\", and \"()\".")));
2200 switch (flags_str[0])
2209 (
errcode(ERRCODE_SYNTAX_ERROR),
2210 errmsg(
"invalid range bound flags"),
2211 errhint(
"Valid values are \"[]\", \"[)\", \"(]\", and \"()\".")));
2214 switch (flags_str[1])
2223 (
errcode(ERRCODE_SYNTAX_ERROR),
2224 errmsg(
"invalid range bound flags"),
2225 errhint(
"Valid values are \"[]\", \"[)\", \"(]\", and \"()\".")));
2264 char **ubound_str,
Node *escontext)
2266 const char *ptr =
string;
2272 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
2286 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
2292 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2293 errmsg(
"malformed range literal: \"%s\"",
2295 errdetail(
"Junk after \"empty\" key word.")));
2305 else if (*ptr ==
'(')
2309 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2310 errmsg(
"malformed range literal: \"%s\"",
2312 errdetail(
"Missing left parenthesis or bracket.")));
2324 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2325 errmsg(
"malformed range literal: \"%s\"",
2327 errdetail(
"Missing comma after lower bound.")));
2340 else if (*ptr ==
')')
2344 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2345 errmsg(
"malformed range literal: \"%s\"",
2350 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
2355 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2356 errmsg(
"malformed range literal: \"%s\"",
2358 errdetail(
"Junk after right parenthesis or bracket.")));
2380 char **bound_str,
bool *infinite,
Node *escontext)
2385 if (*ptr ==
',' || *ptr ==
')' || *ptr ==
']')
2393 bool inquote =
false;
2396 while (inquote || !(*ptr ==
',' || *ptr ==
')' || *ptr ==
']'))
2402 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2403 errmsg(
"malformed range literal: \"%s\"",
2405 errdetail(
"Unexpected end of input.")));
2410 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2411 errmsg(
"malformed range literal: \"%s\"",
2413 errdetail(
"Unexpected end of input.")));
2420 else if (*ptr ==
'"')
2432 *bound_str =
buf.data;
2487 nq = (
value[0] ==
'\0');
2488 for (ptr =
value; *ptr; ptr++)
2492 if (ch ==
'"' || ch ==
'\\' ||
2493 ch ==
'(' || ch ==
')' ||
2494 ch ==
'[' || ch ==
']' ||
2496 isspace((
unsigned char) ch))
2506 for (ptr =
value; *ptr; ptr++)
2510 if (ch ==
'"' || ch ==
'\\')
2538 elog(
ERROR,
"range types do not match");
2580 if (!
lower.infinite)
2591 if (!
upper.infinite)
2615 #define TYPE_IS_PACKABLE(typlen, typstorage) \
2616 ((typlen) == -1 && (typstorage) != TYPSTORAGE_PLAIN)
2624 int16 typlen,
char typstorage)
2650 int16 typlen,
char typstorage)
2659 data_length = typlen;
2661 else if (typlen == -1)
2672 elog(
ERROR,
"cannot store a toast pointer inside a range");
2679 memcpy(ptr,
val, data_length);
2687 memcpy(ptr + 1,
VARDATA(
val), data_length - 1);
2694 memcpy(ptr,
val, data_length);
2697 else if (typlen == -2)
2709 data_length = typlen;
Datum numeric_sub(PG_FUNCTION_ARGS)
Datum numeric_float8(PG_FUNCTION_ARGS)
#define OidIsValid(objectId)
static Datum DateADTGetDatum(DateADT X)
#define DATE_NOT_FINITE(j)
static DateADT DatumGetDateADT(Datum X)
elog(ERROR, "%s: %s", p2, msg)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Datum Int64GetDatum(int64 X)
bool InputFunctionCallSafe(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod, fmNodePtr escontext, Datum *result)
Oid get_fn_expr_argtype(FmgrInfo *flinfo, int argnum)
bytea * SendFunctionCall(FmgrInfo *flinfo, Datum val)
Datum FunctionCall1Coll(FmgrInfo *flinfo, Oid collation, Datum arg1)
Oid get_fn_expr_rettype(FmgrInfo *flinfo)
char * OutputFunctionCall(FmgrInfo *flinfo, Datum val)
Datum ReceiveFunctionCall(FmgrInfo *flinfo, StringInfo buf, Oid typioparam, int32 typmod)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_GETARG_TEXT_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
#define PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define LOCAL_FCINFO(name, nargs)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_DETOAST_DATUM_PACKED(datum)
#define PG_RETURN_UINT64(x)
#define FunctionCallInvoke(fcinfo)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_BOOL(x)
#define ROTATE_HIGH_AND_LOW_32BITS(v)
static Datum hash_uint32(uint32 k)
static Datum hash_uint32_extended(uint32 k, uint64 seed)
if(TABLE==NULL||TABLE_index==NULL)
Assert(fmt[strlen(fmt) - 1] !='\n')
bool type_is_range(Oid typid)
void get_type_io_data(Oid typid, IOFuncSelector which_func, int16 *typlen, bool *typbyval, char *typalign, char *typdelim, Oid *typioparam, Oid *func)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
void * MemoryContextAlloc(MemoryContext context, Size size)
#define SOFT_ERROR_OCCURRED(escontext)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Datum lower(PG_FUNCTION_ARGS)
Datum upper(PG_FUNCTION_ARGS)
static uint32 pg_rotate_left32(uint32 word, int n)
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
void check_stack_depth(void)
static uint32 DatumGetUInt32(Datum X)
static uint64 DatumGetUInt64(Datum X)
static bool DatumGetBool(Datum X)
static int64 DatumGetInt64(Datum X)
static Datum PointerGetDatum(const void *X)
static char * DatumGetCString(Datum X)
static float8 DatumGetFloat8(Datum X)
static Pointer DatumGetPointer(Datum X)
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
Datum range_empty(PG_FUNCTION_ARGS)
Datum range_out(PG_FUNCTION_ARGS)
Datum tstzrange_subdiff(PG_FUNCTION_ARGS)
Datum range_lower(PG_FUNCTION_ARGS)
bool range_ne_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
int range_cmp_bounds(TypeCacheEntry *typcache, const RangeBound *b1, const RangeBound *b2)
Datum hash_range(PG_FUNCTION_ARGS)
Datum range_cmp(PG_FUNCTION_ARGS)
Datum range_in(PG_FUNCTION_ARGS)
bool range_split_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2, RangeType **output1, RangeType **output2)
Datum daterange_canonical(PG_FUNCTION_ARGS)
Datum range_le(PG_FUNCTION_ARGS)
Datum range_before(PG_FUNCTION_ARGS)
Datum int4range_subdiff(PG_FUNCTION_ARGS)
Datum int8range_canonical(PG_FUNCTION_ARGS)
bool range_contained_by_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
#define TYPE_IS_PACKABLE(typlen, typstorage)
Datum range_lower_inc(PG_FUNCTION_ARGS)
Datum range_intersect_agg_transfn(PG_FUNCTION_ARGS)
bool range_contains_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
bool range_after_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
static bool range_parse(const char *string, char *flags, char **lbound_str, char **ubound_str, Node *escontext)
static char * range_deparse(char flags, const char *lbound_str, const char *ubound_str)
bool bounds_adjacent(TypeCacheEntry *typcache, RangeBound boundA, RangeBound boundB)
bool range_overlaps_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
Datum range_lower_inf(PG_FUNCTION_ARGS)
Datum range_upper_inc(PG_FUNCTION_ARGS)
bool range_before_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
Datum elem_contained_by_range(PG_FUNCTION_ARGS)
static RangeIOData * get_range_io_data(FunctionCallInfo fcinfo, Oid rngtypid, IOFuncSelector func)
Datum range_overleft(PG_FUNCTION_ARGS)
Datum range_contained_by(PG_FUNCTION_ARGS)
static Pointer datum_write(Pointer ptr, Datum datum, bool typbyval, char typalign, int16 typlen, char typstorage)
Datum range_constructor2(PG_FUNCTION_ARGS)
Datum range_adjacent(PG_FUNCTION_ARGS)
Datum range_gt(PG_FUNCTION_ARGS)
bool range_overright_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
bool range_contains_elem_internal(TypeCacheEntry *typcache, const RangeType *r, Datum val)
Datum range_overright(PG_FUNCTION_ARGS)
Datum range_contains(PG_FUNCTION_ARGS)
RangeType * range_minus_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2)
RangeType * make_range(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty, struct Node *escontext)
Datum range_intersect(PG_FUNCTION_ARGS)
Datum range_eq(PG_FUNCTION_ARGS)
Datum range_recv(PG_FUNCTION_ARGS)
void range_deserialize(TypeCacheEntry *typcache, const RangeType *range, RangeBound *lower, RangeBound *upper, bool *empty)
Datum daterange_subdiff(PG_FUNCTION_ARGS)
TypeCacheEntry * range_get_typcache(FunctionCallInfo fcinfo, Oid rngtypid)
static char * range_bound_escape(const char *value)
Datum range_lt(PG_FUNCTION_ARGS)
static Size datum_compute_size(Size data_length, Datum val, bool typbyval, char typalign, int16 typlen, char typstorage)
Datum int8range_subdiff(PG_FUNCTION_ARGS)
bool range_eq_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
Datum range_upper_inf(PG_FUNCTION_ARGS)
Datum int4range_canonical(PG_FUNCTION_ARGS)
Datum range_ge(PG_FUNCTION_ARGS)
Datum range_overlaps(PG_FUNCTION_ARGS)
Datum range_upper(PG_FUNCTION_ARGS)
bool range_adjacent_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
void range_set_contain_empty(RangeType *range)
Datum range_constructor3(PG_FUNCTION_ARGS)
char range_get_flags(const RangeType *range)
Datum hash_range_extended(PG_FUNCTION_ARGS)
static const char * range_parse_bound(const char *string, const char *ptr, char **bound_str, bool *infinite, Node *escontext)
RangeType * make_empty_range(TypeCacheEntry *typcache)
static char range_parse_flags(const char *flags_str)
Datum tsrange_subdiff(PG_FUNCTION_ARGS)
bool range_overleft_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
int range_compare(const void *key1, const void *key2, void *arg)
struct RangeIOData RangeIOData
Datum range_after(PG_FUNCTION_ARGS)
Datum range_union(PG_FUNCTION_ARGS)
Datum range_minus(PG_FUNCTION_ARGS)
Datum range_ne(PG_FUNCTION_ARGS)
RangeType * range_union_internal(TypeCacheEntry *typcache, RangeType *r1, RangeType *r2, bool strict)
RangeType * range_intersect_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
int range_cmp_bound_values(TypeCacheEntry *typcache, const RangeBound *b1, const RangeBound *b2)
Datum range_merge(PG_FUNCTION_ARGS)
Datum range_send(PG_FUNCTION_ARGS)
Datum range_contains_elem(PG_FUNCTION_ARGS)
RangeType * range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty, struct Node *escontext)
Datum numrange_subdiff(PG_FUNCTION_ARGS)
#define RANGE_CONTAIN_EMPTY
#define RANGE_HAS_UBOUND(flags)
static Datum RangeTypePGetDatum(const RangeType *X)
#define PG_RETURN_RANGE_P(x)
#define RANGE_HAS_LBOUND(flags)
static RangeType * DatumGetRangeTypeP(Datum X)
#define PG_GETARG_RANGE_P(n)
#define RANGE_EMPTY_LITERAL
#define RangeTypeGetOid(r)
static struct cvec * range(struct vars *v, chr a, chr b, int cases)
static int cmp(const chr *x, const chr *y, size_t len)
StringInfo makeStringInfo(void)
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
TypeCacheEntry * typcache
FmgrInfo rng_cmp_proc_finfo
struct TypeCacheEntry * rngelemtype
FmgrInfo hash_extended_proc_finfo
FmgrInfo rng_canonical_finfo
#define att_align_pointer(cur_offset, attalign, attlen, attptr)
#define att_align_nominal(cur_offset, attalign)
#define att_align_datum(cur_offset, attalign, attlen, attdatum)
#define att_addlength_pointer(cur_offset, attlen, attptr)
static Datum fetch_att(const void *T, bool attbyval, int attlen)
#define att_addlength_datum(cur_offset, attlen, attdatum)
static void store_att_byval(void *T, Datum newdatum, int attlen)
TypeCacheEntry * lookup_type_cache(Oid type_id, int flags)
#define TYPECACHE_HASH_PROC_FINFO
#define TYPECACHE_RANGE_INFO
#define TYPECACHE_HASH_EXTENDED_PROC_FINFO
#define PG_GETARG_TIMESTAMP(n)
#define VARSIZE_SHORT(PTR)
#define SET_VARSIZE_SHORT(PTR, len)
#define VARATT_CAN_MAKE_SHORT(PTR)
#define VARATT_IS_SHORT(PTR)
#define SET_VARSIZE(PTR, len)
#define VARATT_CONVERTED_SHORT_SIZE(PTR)
#define VARATT_IS_EXTERNAL(PTR)
char * text_to_cstring(const text *t)