41#include "utils/fmgrprotos.h"
44#define HEXDIG(z) ((z)<10 ? ((z)+'0') : ((z)-10+'A'))
47#define VARBIT_PAD(vb) \
49 int32 pad_ = VARBITPAD(vb); \
50 Assert(pad_ >= 0 && pad_ < BITS_PER_BYTE); \
52 *(VARBITS(vb) + VARBITBYTES(vb) - 1) &= BITMASK << pad_; \
59#define VARBIT_PAD_LAST(vb, ptr) \
61 int32 pad_ = VARBITPAD(vb); \
62 Assert(pad_ >= 0 && pad_ < BITS_PER_BYTE); \
64 *((ptr) - 1) &= BITMASK << pad_; \
68#ifdef USE_ASSERT_CHECKING
69#define VARBIT_CORRECTLY_PADDED(vb) \
71 int32 pad_ = VARBITPAD(vb); \
72 Assert(pad_ >= 0 && pad_ < BITS_PER_BYTE); \
74 (*(VARBITS(vb) + VARBITBYTES(vb) - 1) & ~(BITMASK << pad_)) == 0); \
77#define VARBIT_CORRECTLY_PADDED(vb) ((void) 0)
105 errmsg(
"invalid type modifier")));
110 errmsg(
"length for type %s must be at least 1",
115 errmsg(
"length for type %s cannot exceed %d",
129 char *res = (
char *)
palloc(64);
154 Node *escontext = fcinfo->context;
198 errmsg(
"bit string length exceeds the maximum allowed (%d)",
209 else if (
bitlen != atttypmod)
212 errmsg(
"bit string length %d does not match type bit(%d)",
234 errmsg(
"\"%.*s\" is not a valid binary digit",
248 for (bc = 0; *
sp;
sp++)
250 if (*
sp >=
'0' && *
sp <=
'9')
252 else if (*
sp >=
'A' && *
sp <=
'F')
254 else if (*
sp >=
'a' && *
sp <=
'f')
259 errmsg(
"\"%.*s\" is not a valid hexadecimal digit",
347 errmsg(
"invalid length in external bit string")));
353 if (atttypmod > 0 &&
bitlen != atttypmod)
356 errmsg(
"bit string length %d does not match type bit(%d)",
406 errmsg(
"bit string length %d does not match type bit(%d)",
459 Node *escontext = fcinfo->context;
499 errmsg(
"bit string length exceeds the maximum allowed (%d)",
510 else if (
bitlen > atttypmod)
513 errmsg(
"bit string too long for type bit varying(%d)",
535 errmsg(
"\"%.*s\" is not a valid binary digit",
549 for (bc = 0; *
sp;
sp++)
551 if (*
sp >=
'0' && *
sp <=
'9')
553 else if (*
sp >=
'A' && *
sp <=
'F')
555 else if (*
sp >=
'a' && *
sp <=
'f')
560 errmsg(
"\"%.*s\" is not a valid hexadecimal digit",
619 for (k =
i; k <
len; k++)
652 errmsg(
"invalid length in external bit string")));
658 if (atttypmod > 0 &&
bitlen > atttypmod)
661 errmsg(
"bit string too long for type bit varying(%d)",
757 errmsg(
"bit string too long for type bit varying(%d)",
994 errmsg(
"bit string length exceeds the maximum allowed (%d)",
1081 errmsg(
"negative substring length not allowed")));
1129 for (
i = 0;
i <
len;
i++)
1191 errmsg(
"negative substring length not allowed")));
1195 errmsg(
"integer out of range")));
1261 errmsg(
"cannot AND bit strings of different sizes")));
1272 *r++ = *
p1++ & *
p2++;
1302 errmsg(
"cannot OR bit strings of different sizes")));
1312 *r++ = *
p1++ | *
p2++;
1342 errmsg(
"cannot XOR bit strings of different sizes")));
1353 *r++ = *
p1++ ^ *
p2++;
1596 errmsg(
"integer out of range")));
1676 errmsg(
"bigint out of range")));
1824 errmsg(
"bit index %d out of valid range (0..%d)",
1833 errmsg(
"new bit must be 0 or 1")));
1882 errmsg(
"bit index %d out of valid range (0..%d)",
#define PG_GETARG_ARRAYTYPE_P(n)
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
#define IS_HIGHBIT_SET(ch)
#define Assert(condition)
#define MemSet(start, val, len)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_RETURN_INT64(x)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_BOOL(x)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
int pg_mblen(const char *mbstr)
void * palloc0(Size size)
int32 exprTypmod(const Node *expr)
Node * relabel_to_typmod(Node *expr, int32 typmod)
#define IsA(nodeptr, _type_)
static uint64 pg_popcount(const char *buf, int bytes)
static int list_length(const List *l)
static rewind_source * source
static char buf[DEFAULT_XLOG_SEG_SIZE]
static Datum Int32GetDatum(int32 X)
static int32 DatumGetInt32(Datum X)
static int cmp(const chr *x, const chr *y, size_t len)
struct StringInfoData * StringInfo
static Size VARSIZE(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
Datum bitoverlay(PG_FUNCTION_ARGS)
Datum bitfromint4(PG_FUNCTION_ARGS)
Datum bitxor(PG_FUNCTION_ARGS)
Datum bitcmp(PG_FUNCTION_ARGS)
Datum bitcat(PG_FUNCTION_ARGS)
Datum bittoint4(PG_FUNCTION_ARGS)
Datum varbit_send(PG_FUNCTION_ARGS)
Datum bitfromint8(PG_FUNCTION_ARGS)
#define VARBIT_CORRECTLY_PADDED(vb)
Datum varbittypmodin(PG_FUNCTION_ARGS)
Datum bitoverlay_no_len(PG_FUNCTION_ARGS)
static char * anybit_typmodout(int32 typmod)
Datum bit(PG_FUNCTION_ARGS)
Datum bit_send(PG_FUNCTION_ARGS)
Datum varbit(PG_FUNCTION_ARGS)
Datum bitne(PG_FUNCTION_ARGS)
Datum bittypmodout(PG_FUNCTION_ARGS)
Datum varbit_out(PG_FUNCTION_ARGS)
Datum varbit_support(PG_FUNCTION_ARGS)
Datum bit_out(PG_FUNCTION_ARGS)
static int32 anybit_typmodin(ArrayType *ta, const char *typename)
Datum bitgetbit(PG_FUNCTION_ARGS)
Datum bitsetbit(PG_FUNCTION_ARGS)
Datum bit_bit_count(PG_FUNCTION_ARGS)
Datum bit_and(PG_FUNCTION_ARGS)
Datum varbit_recv(PG_FUNCTION_ARGS)
Datum bitge(PG_FUNCTION_ARGS)
static VarBit * bit_catenate(VarBit *arg1, VarBit *arg2)
Datum bitle(PG_FUNCTION_ARGS)
static VarBit * bit_overlay(VarBit *t1, VarBit *t2, int sp, int sl)
#define VARBIT_PAD_LAST(vb, ptr)
Datum biteq(PG_FUNCTION_ARGS)
Datum bitsubstr_no_len(PG_FUNCTION_ARGS)
static VarBit * bitsubstring(VarBit *arg, int32 s, int32 l, bool length_not_specified)
Datum bitlt(PG_FUNCTION_ARGS)
Datum bittoint8(PG_FUNCTION_ARGS)
Datum bit_or(PG_FUNCTION_ARGS)
Datum bitgt(PG_FUNCTION_ARGS)
Datum bittypmodin(PG_FUNCTION_ARGS)
Datum bitposition(PG_FUNCTION_ARGS)
Datum bitoctetlength(PG_FUNCTION_ARGS)
Datum bit_in(PG_FUNCTION_ARGS)
Datum bit_recv(PG_FUNCTION_ARGS)
Datum bitsubstr(PG_FUNCTION_ARGS)
Datum varbittypmodout(PG_FUNCTION_ARGS)
Datum bitshiftright(PG_FUNCTION_ARGS)
Datum bitnot(PG_FUNCTION_ARGS)
Datum bitshiftleft(PG_FUNCTION_ARGS)
Datum bitlength(PG_FUNCTION_ARGS)
Datum varbit_in(PG_FUNCTION_ARGS)
static int32 bit_cmp(VarBit *arg1, VarBit *arg2)
#define PG_RETURN_VARBIT_P(x)
#define PG_GETARG_VARBIT_P(n)
static Datum VarBitPGetDatum(const VarBit *X)
#define VARBITTOTALLEN(BITLEN)