18#include "catalog/pg_collation_d.h"
19#include "catalog/pg_type_d.h"
26#include "utils/fmgrprotos.h"
37 bool length_not_specified);
80#define PG_STR_GET_BYTEA(str_) \
81 DatumGetByteaPP(DirectFunctionCall1(byteain, CStringGetDatum(str_)))
87 bool length_not_specified)
98 if (length_not_specified)
110 (
errcode(ERRCODE_SUBSTRING_ERROR),
111 errmsg(
"negative substring length not allowed")));
158 (
errcode(ERRCODE_SUBSTRING_ERROR),
159 errmsg(
"negative substring length not allowed")));
162 (
errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
163 errmsg(
"integer out of range")));
177#define VAL(CH) ((CH) - '0')
178#define DIG(VAL) ((VAL) + '0')
190 Node *escontext = fcinfo->context;
191 size_t len = strlen(inputText);
198 if (inputText[0] ==
'\\' && inputText[1] ==
'x')
218 else if ((tp[1] >=
'0' && tp[1] <=
'3') &&
219 (tp[2] >=
'0' && tp[2] <=
'7') &&
220 (tp[3] >=
'0' && tp[3] <=
'7'))
228 *rp++ = v +
VAL(tp[3]);
232 else if (tp[1] ==
'\\')
243 (
errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
244 errmsg(
"invalid input syntax for type %s",
"bytea")));
288 else if ((
unsigned char) *vp < 0x20 || (
unsigned char) *vp > 0x7e)
301 (
errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
313 else if ((
unsigned char) *vp < 0x20 || (
unsigned char) *vp > 0x7e)
332 elog(
ERROR,
"unrecognized \"bytea_output\" setting: %d",
350 nbytes =
buf->len -
buf->cursor;
381 bool isfirst =
false;
402 elog(
ERROR,
"bytea_string_agg_transfn called in non-aggregate context");
604 for (p = 0; p <=
px; p++)
606 if ((*p2 == *p1) && (memcmp(p1, p2, len2) == 0))
634 if (n < 0 || n >=
len)
636 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
637 errmsg(
"index %d out of valid range, 0..%d",
667 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
668 errmsg(
"index %" PRId64
" out of valid range, 0..%" PRId64,
672 byteNo = (int) (n / 8);
673 bitNo = (int) (n % 8);
677 if (
byte & (1 << bitNo))
701 if (n < 0 || n >=
len)
703 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
704 errmsg(
"index %d out of valid range, 0..%d",
710 ((
unsigned char *)
VARDATA(res))[n] = newByte;
739 (
errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR),
740 errmsg(
"index %" PRId64
" out of valid range, 0..%" PRId64,
744 byteNo = (int) (n / 8);
745 bitNo = (int) (n % 8);
750 if (newBit != 0 && newBit != 1)
752 (
errcode(ERRCODE_INVALID_PARAMETER_VALUE),
753 errmsg(
"new bit must be 0 or 1")));
758 oldByte = ((
unsigned char *)
VARDATA(res))[byteNo];
761 newByte = oldByte & (~(1 << bitNo));
763 newByte = oldByte | (1 << bitNo);
765 ((
unsigned char *)
VARDATA(res))[byteNo] = newByte;
779 const char *endp = p +
len;
957 if ((
cmp == 0) && (len1 != len2))
958 cmp = (len1 < len2) ? -1 : 1;
980 result = ((
cmp > 0) || ((
cmp == 0) && (len1 > len2)) ? arg1 : arg2);
999 result = ((
cmp < 0) || ((
cmp == 0) && (len1 < len2)) ? arg1 : arg2);
1029 if (
len >
sizeof(result))
1031 errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1032 errmsg(
"smallint out of range"));
1036 for (
int i = 0;
i <
len;
i++)
1054 if (
len >
sizeof(result))
1056 errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1057 errmsg(
"integer out of range"));
1061 for (
int i = 0;
i <
len;
i++)
1079 if (
len >
sizeof(result))
1081 errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1082 errmsg(
"bigint out of range"));
1086 for (
int i = 0;
i <
len;
i++)
Datum byteacat(PG_FUNCTION_ARGS)
Datum byteaoverlay(PG_FUNCTION_ARGS)
Datum byteaeq(PG_FUNCTION_ARGS)
Datum byteagt(PG_FUNCTION_ARGS)
Datum bytea_int2(PG_FUNCTION_ARGS)
Datum bytea_string_agg_finalfn(PG_FUNCTION_ARGS)
Datum int2_bytea(PG_FUNCTION_ARGS)
Datum byteapos(PG_FUNCTION_ARGS)
static bytea * bytea_overlay(bytea *t1, bytea *t2, int sp, int sl)
Datum byteane(PG_FUNCTION_ARGS)
Datum byteage(PG_FUNCTION_ARGS)
Datum byteacmp(PG_FUNCTION_ARGS)
Datum byteaGetBit(PG_FUNCTION_ARGS)
Datum bytea_bit_count(PG_FUNCTION_ARGS)
Datum byteaSetBit(PG_FUNCTION_ARGS)
Datum byteaSetByte(PG_FUNCTION_ARGS)
Datum bytea_substr_no_len(PG_FUNCTION_ARGS)
Datum byteale(PG_FUNCTION_ARGS)
#define PG_STR_GET_BYTEA(str_)
Datum int8_bytea(PG_FUNCTION_ARGS)
Datum bytea_int4(PG_FUNCTION_ARGS)
Datum bytearecv(PG_FUNCTION_ARGS)
Datum bytea_smaller(PG_FUNCTION_ARGS)
Datum bytea_sortsupport(PG_FUNCTION_ARGS)
static bytea * bytea_substring(Datum str, int S, int L, bool length_not_specified)
static bytea * bytea_catenate(bytea *t1, bytea *t2)
Datum bytea_reverse(PG_FUNCTION_ARGS)
Datum byteaoverlay_no_len(PG_FUNCTION_ARGS)
Datum bytea_int8(PG_FUNCTION_ARGS)
Datum bytea_larger(PG_FUNCTION_ARGS)
Datum byteaoctetlen(PG_FUNCTION_ARGS)
Datum byteaout(PG_FUNCTION_ARGS)
Datum byteain(PG_FUNCTION_ARGS)
Datum bytea_string_agg_transfn(PG_FUNCTION_ARGS)
Datum byteaGetByte(PG_FUNCTION_ARGS)
Datum int4_bytea(PG_FUNCTION_ARGS)
Datum bytea_substr(PG_FUNCTION_ARGS)
Datum bytealt(PG_FUNCTION_ARGS)
Datum byteasend(PG_FUNCTION_ARGS)
Size toast_raw_datum_size(Datum value)
int errmsg_internal(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
uint64 hex_decode_safe(const char *src, size_t len, char *dst, Node *escontext)
uint64 hex_encode(const char *src, size_t len, char *dst)
#define PG_FREE_IF_COPY(ptr, n)
#define DatumGetByteaPSlice(X, m, n)
#define PG_GETARG_BYTEA_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DatumGetByteaPP(X)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_RETURN_INT64(x)
#define PG_GETARG_DATUM(n)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_RETURN_INT16(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_RETURN_POINTER(x)
#define PG_GETARG_BYTEA_P_COPY(n)
#define PG_RETURN_BOOL(x)
void px(PlannerInfo *root, Gene *tour1, Gene *tour2, Gene *offspring, int num_gene, City *city_table)
Assert(PointerIsAligned(start, uint64))
Datum int8send(PG_FUNCTION_ARGS)
Datum int2send(PG_FUNCTION_ARGS)
Datum int4send(PG_FUNCTION_ARGS)
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static uint64 pg_popcount(const char *buf, int bytes)
static Datum PointerGetDatum(const void *X)
static int cmp(const chr *x, const chr *y, size_t len)
struct SortSupportData * SortSupport
struct StringInfoData * StringInfo
StringInfo makeStringInfo(void)
void appendBinaryStringInfo(StringInfo str, const void *data, int datalen)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static Size VARSIZE(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
void varstr_sortsupport(SortSupport ssup, Oid typid, Oid collid)