58 static void range_parse(
const char *input_str,
char *flags,
char **lbound_str,
61 char **bound_str,
bool *infinite);
62 static char *
range_deparse(
char flags,
const char *lbound_str,
63 const char *ubound_str);
96 range_parse(input_str, &flags, &lbound_str, &ubound_str);
126 char *lbound_str = NULL;
127 char *ubound_str = NULL;
271 char *bound_data =
VARDATA(bound);
282 char *bound_data =
VARDATA(bound);
315 elog(
ERROR,
"type %u is not a range type", rngtypid);
332 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
333 errmsg(
"no binary input function available for type %s",
337 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
338 errmsg(
"no binary output function available for type %s",
373 lower.inclusive =
true;
378 upper.inclusive =
false;
403 (
errcode(ERRCODE_DATA_EXCEPTION),
404 errmsg(
"range constructor flags argument must not be null")));
441 if (empty ||
lower.infinite)
462 if (empty ||
upper.infinite)
571 if (empty1 && empty2)
573 if (empty1 != empty2)
663 if (empty1 || empty2)
701 if (empty1 || empty2)
768 boundB.
lower =
false;
769 r =
make_range(typcache, &boundA, &boundB,
false);
797 if (empty1 || empty2)
840 if (empty1 || empty2)
886 if (empty1 || empty2)
927 if (empty1 || empty2)
992 if (empty1 || empty2)
1000 if (cmp_l1l2 < 0 && cmp_u1u2 > 0)
1002 (
errcode(ERRCODE_DATA_EXCEPTION),
1003 errmsg(
"result of range difference would not be contiguous")));
1005 if (cmp_l1u2 > 0 || cmp_u1l2 < 0)
1008 if (cmp_l1l2 >= 0 && cmp_u1u2 <= 0)
1011 if (cmp_l1l2 <= 0 && cmp_u1l2 >= 0 && cmp_u1u2 <= 0)
1014 lower2.
lower =
false;
1015 return make_range(typcache, &lower1, &lower2,
false);
1018 if (cmp_l1l2 >= 0 && cmp_u1u2 >= 0 && cmp_l1u2 <= 0)
1021 upper2.
lower =
true;
1022 return make_range(typcache, &upper2, &upper1,
false);
1025 elog(
ERROR,
"unexpected case in range_minus");
1048 elog(
ERROR,
"range types do not match");
1063 (
errcode(ERRCODE_DATA_EXCEPTION),
1064 errmsg(
"result of range union would not be contiguous")));
1067 result_lower = &lower1;
1069 result_lower = &lower2;
1072 result_upper = &upper1;
1074 result_upper = &upper2;
1076 return make_range(typcache, result_lower, result_upper,
false);
1117 elog(
ERROR,
"range types do not match");
1143 result_lower = &lower1;
1145 result_lower = &lower2;
1148 result_upper = &upper1;
1150 result_upper = &upper2;
1152 return make_range(typcache, result_lower, result_upper,
false);
1186 lower2.
lower =
false;
1188 upper2.
lower =
true;
1190 *output1 =
make_range(typcache, &lower1, &lower2,
false);
1191 *output2 =
make_range(typcache, &upper2, &upper1,
false);
1210 elog(
ERROR,
"range_intersect_agg_transfn called in non-aggregate context");
1214 elog(
ERROR,
"range_intersect_agg must be called with a range");
1248 elog(
ERROR,
"range types do not match");
1256 if (empty1 && empty2)
1342 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1343 errmsg(
"could not identify a hash function for type %s",
1366 result ^= lower_hash;
1368 result ^= upper_hash;
1406 (
errcode(ERRCODE_UNDEFINED_FUNCTION),
1407 errmsg(
"could not identify a hash function for type %s",
1430 result ^= lower_hash;
1432 result ^= upper_hash;
1464 lower.inclusive =
true;
1470 upper.inclusive =
false;
1495 lower.inclusive =
true;
1501 upper.inclusive =
false;
1527 lower.inclusive =
true;
1534 upper.inclusive =
false;
1639 if (typcache == NULL ||
1640 typcache->
type_id != rngtypid)
1644 elog(
ERROR,
"type %u is not a range type", rngtypid);
1688 (
errcode(ERRCODE_DATA_EXCEPTION),
1689 errmsg(
"range lower bound must be less than or equal to range upper bound")));
1697 if (
lower->infinite)
1699 else if (
lower->inclusive)
1701 if (
upper->infinite)
1703 else if (
upper->inclusive)
1734 typlen, typstorage);
1744 typlen, typstorage);
1748 msize +=
sizeof(char);
1757 ptr = (
char *) (
range + 1);
1773 *((
char *) ptr) = flags;
1817 lbound =
fetch_att(ptr, typbyval, typlen);
1827 ubound =
fetch_att(ptr, typbyval, typlen);
1837 lower->val = lbound;
1840 lower->lower =
true;
1842 upper->val = ubound;
1845 upper->lower =
false;
1941 return b1->
lower ? -1 : 1;
1944 return b1->
lower ? -1 : 1;
1946 return b2->
lower ? 1 : -1;
1968 return b1->
lower ? 1 : -1;
1971 return b1->
lower ? 1 : -1;
1973 return b2->
lower ? -1 : 1;
2014 return b1->
lower ? -1 : 1;
2017 return b1->
lower ? -1 : 1;
2019 return b2->
lower ? 1 : -1;
2053 if (empty1 && empty2)
2079 lower.infinite =
false;
2080 lower.inclusive =
false;
2084 upper.infinite =
false;
2085 upper.inclusive =
false;
2086 upper.lower =
false;
2107 if (flags_str[0] ==
'\0' ||
2108 flags_str[1] ==
'\0' ||
2109 flags_str[2] !=
'\0')
2111 (
errcode(ERRCODE_SYNTAX_ERROR),
2112 errmsg(
"invalid range bound flags"),
2113 errhint(
"Valid values are \"[]\", \"[)\", \"(]\", and \"()\".")));
2115 switch (flags_str[0])
2124 (
errcode(ERRCODE_SYNTAX_ERROR),
2125 errmsg(
"invalid range bound flags"),
2126 errhint(
"Valid values are \"[]\", \"[)\", \"(]\", and \"()\".")));
2129 switch (flags_str[1])
2138 (
errcode(ERRCODE_SYNTAX_ERROR),
2139 errmsg(
"invalid range bound flags"),
2140 errhint(
"Valid values are \"[]\", \"[)\", \"(]\", and \"()\".")));
2178 const char *ptr =
string;
2184 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
2198 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
2204 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2205 errmsg(
"malformed range literal: \"%s\"",
2207 errdetail(
"Junk after \"empty\" key word.")));
2217 else if (*ptr ==
'(')
2221 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2222 errmsg(
"malformed range literal: \"%s\"",
2224 errdetail(
"Missing left parenthesis or bracket.")));
2234 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2235 errmsg(
"malformed range literal: \"%s\"",
2237 errdetail(
"Missing comma after lower bound.")));
2248 else if (*ptr ==
')')
2252 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2253 errmsg(
"malformed range literal: \"%s\"",
2258 while (*ptr !=
'\0' && isspace((
unsigned char) *ptr))
2263 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2264 errmsg(
"malformed range literal: \"%s\"",
2266 errdetail(
"Junk after right parenthesis or bracket.")));
2285 char **bound_str,
bool *infinite)
2290 if (*ptr ==
',' || *ptr ==
')' || *ptr ==
']')
2298 bool inquote =
false;
2301 while (inquote || !(*ptr ==
',' || *ptr ==
')' || *ptr ==
']'))
2307 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2308 errmsg(
"malformed range literal: \"%s\"",
2310 errdetail(
"Unexpected end of input.")));
2315 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
2316 errmsg(
"malformed range literal: \"%s\"",
2318 errdetail(
"Unexpected end of input.")));
2325 else if (*ptr ==
'"')
2337 *bound_str =
buf.data;
2392 nq = (
value[0] ==
'\0');
2393 for (ptr =
value; *ptr; ptr++)
2397 if (ch ==
'"' || ch ==
'\\' ||
2398 ch ==
'(' || ch ==
')' ||
2399 ch ==
'[' || ch ==
']' ||
2401 isspace((
unsigned char) ch))
2411 for (ptr =
value; *ptr; ptr++)
2415 if (ch ==
'"' || ch ==
'\\')
2443 elog(
ERROR,
"range types do not match");
2485 if (!
lower.infinite)
2496 if (!
upper.infinite)
2520 #define TYPE_IS_PACKABLE(typlen, typstorage) \
2521 ((typlen) == -1 && (typstorage) != TYPSTORAGE_PLAIN)
2529 int16 typlen,
char typstorage)
2555 int16 typlen,
char typstorage)
2564 data_length = typlen;
2566 else if (typlen == -1)
2577 elog(
ERROR,
"cannot store a toast pointer inside a range");
2584 memcpy(ptr,
val, data_length);
2592 memcpy(ptr + 1,
VARDATA(
val), data_length - 1);
2599 memcpy(ptr,
val, data_length);
2602 else if (typlen == -2)
2614 data_length = typlen;
Datum numeric_sub(PG_FUNCTION_ARGS)
Datum numeric_float8(PG_FUNCTION_ARGS)
#define OidIsValid(objectId)
Datum date_pli(PG_FUNCTION_ARGS)
#define DATE_NOT_FINITE(j)
#define DatumGetDateADT(X)
int errdetail(const char *fmt,...)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
Datum InputFunctionCall(FmgrInfo *flinfo, char *str, Oid typioparam, int32 typmod)
Datum FunctionCall2Coll(FmgrInfo *flinfo, Oid collation, Datum arg1, Datum arg2)
void fmgr_info_cxt(Oid functionId, FmgrInfo *finfo, MemoryContext mcxt)
Datum Int64GetDatum(int64 X)
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 PG_RETURN_CSTRING(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_DETOAST_DATUM_PACKED(datum)
#define PG_RETURN_UINT64(x)
#define FunctionCall1(flinfo, arg1)
#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)
Datum int8pl(PG_FUNCTION_ARGS)
Datum int4pl(PG_FUNCTION_ARGS)
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)
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)
#define VARSIZE_SHORT(PTR)
#define SET_VARSIZE_SHORT(PTR, len)
#define VARATT_CAN_MAKE_SHORT(PTR)
#define VARATT_IS_SHORT(PTR)
#define DatumGetPointer(X)
#define DatumGetUInt64(X)
#define DatumGetFloat8(X)
#define SET_VARSIZE(PTR, len)
#define VARATT_CONVERTED_SHORT_SIZE(PTR)
#define VARATT_IS_EXTERNAL(PTR)
#define DatumGetCString(X)
#define PointerGetDatum(X)
#define DatumGetUInt32(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)
RangeType * range_serialize(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
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)
static const char * range_parse_bound(const char *string, const char *ptr, char **bound_str, bool *infinite)
bool range_after_internal(TypeCacheEntry *typcache, const RangeType *r1, const RangeType *r2)
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)
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)
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)
static void range_parse(const char *input_str, char *flags, char **lbound_str, char **ubound_str)
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)
RangeType * make_empty_range(TypeCacheEntry *typcache)
static Size datum_compute_size(Size sz, Datum datum, bool typbyval, char typalign, int16 typlen, char typstorage)
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)
RangeType * make_range(TypeCacheEntry *typcache, RangeBound *lower, RangeBound *upper, bool empty)
Datum range_contains_elem(PG_FUNCTION_ARGS)
Datum numrange_subdiff(PG_FUNCTION_ARGS)
#define RangeTypePGetDatum(X)
#define RANGE_CONTAIN_EMPTY
#define RANGE_HAS_UBOUND(flags)
#define PG_RETURN_RANGE_P(x)
#define DatumGetRangeTypeP(X)
#define RANGE_HAS_LBOUND(flags)
#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 char *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 store_att_byval(T, newdatum, attlen)
#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)
#define fetch_att(T, attbyval, attlen)
#define att_addlength_datum(cur_offset, attlen, attdatum)
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)
char * text_to_cstring(const text *t)