本文整理汇总了C++中PG_GETARG_INT32函数的典型用法代码示例。如果您正苦于以下问题:C++ PG_GETARG_INT32函数的具体用法?C++ PG_GETARG_INT32怎么用?C++ PG_GETARG_INT32使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PG_GETARG_INT32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: compute_shortest_path_shooting_star
//.........这里部分代码省略.........
{
ereport(ERROR, (errcode(ERRCODE_E_R_E_CONTAINING_SQL_NOT_PERMITTED),
errmsg("Error computing path: %s", err_msg)));
}
return finish(SPIcode, ret);
}
PG_FUNCTION_INFO_V1(shortest_path_shooting_star);
Datum
shortest_path_shooting_star(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
int call_cntr;
int max_calls;
TupleDesc tuple_desc;
path_element_t *path = 0;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
{
MemoryContext oldcontext;
int path_count = 0;
int ret;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/* switch to memory context appropriate for multiple function calls */
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
ret = compute_shortest_path_shooting_star(text2char(PG_GETARG_TEXT_P(0)),
PG_GETARG_INT32(1),
PG_GETARG_INT32(2),
PG_GETARG_BOOL(3),
PG_GETARG_BOOL(4),
&path, &path_count);
#ifdef DEBUG
DBG("Ret is %i", ret);
if (ret >= 0)
{
int i;
for (i = 0; i < path_count; i++)
{
DBG("Step # %i vertex_id %i ", i, path[i].vertex_id);
DBG(" edge_id %i ", path[i].edge_id);
DBG(" cost %f ", path[i].cost);
}
}
#endif
/* total number of tuples to be returned */
DBG("Conting tuples number\n");
funcctx->max_calls = path_count;
funcctx->user_fctx = path;
DBG("Path count %i", path_count);
funcctx->tuple_desc =
BlessTupleDesc(RelationNameGetTupleDesc("pgr_costResult"));
MemoryContextSwitchTo(oldcontext);
}
示例2: geography_as_geojson
Datum geography_as_geojson(PG_FUNCTION_ARGS)
{
LWGEOM *lwgeom = NULL;
GSERIALIZED *g = NULL;
char *geojson;
text *result;
int version;
int option = 0;
int has_bbox = 0;
int precision = OUT_MAX_DOUBLE_PRECISION;
char * srs = NULL;
/* Get the version */
version = PG_GETARG_INT32(0);
if ( version != 1)
{
elog(ERROR, "Only GeoJSON 1 is supported");
PG_RETURN_NULL();
}
/* Get the geography */
if (PG_ARGISNULL(1) ) PG_RETURN_NULL();
g = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
/* Convert to lwgeom so we can run the old functions */
lwgeom = lwgeom_from_gserialized(g);
/* Retrieve precision if any (default is max) */
if (PG_NARGS() >2 && !PG_ARGISNULL(2))
{
precision = PG_GETARG_INT32(2);
if ( precision > OUT_MAX_DOUBLE_PRECISION )
precision = OUT_MAX_DOUBLE_PRECISION;
else if ( precision < 0 ) precision = 0;
}
/* Retrieve output option
* 0 = without option (default)
* 1 = bbox
* 2 = short crs
* 4 = long crs
*/
if (PG_NARGS() >3 && !PG_ARGISNULL(3))
option = PG_GETARG_INT32(3);
if (option & 2 || option & 4)
{
/* Geography only handle srid SRID_DEFAULT */
if (option & 2) srs = getSRSbySRID(SRID_DEFAULT, true);
if (option & 4) srs = getSRSbySRID(SRID_DEFAULT, false);
if (!srs)
{
elog(ERROR, "SRID SRID_DEFAULT unknown in spatial_ref_sys table");
PG_RETURN_NULL();
}
}
if (option & 1) has_bbox = 1;
geojson = lwgeom_to_geojson(lwgeom, srs, precision, has_bbox);
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(g, 1);
if (srs) pfree(srs);
result = cstring2text(geojson);
lwfree(geojson);
PG_RETURN_TEXT_P(result);
}
示例3: gin_consistent_jsonb
Datum
gin_consistent_jsonb(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
/* Jsonb *query = PG_GETARG_JSONB(2); */
int32 nkeys = PG_GETARG_INT32(3);
/* Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4); */
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res = true;
int32 i;
if (strategy == JsonbContainsStrategyNumber)
{
/*
* We must always recheck, since we can't tell from the index whether
* the positions of the matched items match the structure of the query
* object. (Even if we could, we'd also have to worry about hashed
* keys and the index's failure to distinguish keys from string array
* elements.) However, the tuple certainly doesn't match unless it
* contains all the query keys.
*/
*recheck = true;
for (i = 0; i < nkeys; i++)
{
if (!check[i])
{
res = false;
break;
}
}
}
else if (strategy == JsonbExistsStrategyNumber)
{
/*
* Although the key is certainly present in the index, we must recheck
* because (1) the key might be hashed, and (2) the index match might
* be for a key that's not at top level of the JSON object. For (1),
* we could look at the query key to see if it's hashed and not
* recheck if not, but the index lacks enough info to tell about (2).
*/
*recheck = true;
res = true;
}
else if (strategy == JsonbExistsAnyStrategyNumber)
{
/* As for plain exists, we must recheck */
*recheck = true;
res = true;
}
else if (strategy == JsonbExistsAllStrategyNumber)
{
/* As for plain exists, we must recheck */
*recheck = true;
/* ... but unless all the keys are present, we can say "false" */
for (i = 0; i < nkeys; i++)
{
if (!check[i])
{
res = false;
break;
}
}
}
else
elog(ERROR, "unrecognized strategy number: %d", strategy);
PG_RETURN_BOOL(res);
}
示例4: record_recv
/*
* record_recv - binary input routine for any composite type.
*/
Datum
record_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
Oid tupType = PG_GETARG_OID(1);
#ifdef NOT_USED
int32 typmod = PG_GETARG_INT32(2);
#endif
HeapTupleHeader result;
int32 tupTypmod;
TupleDesc tupdesc;
HeapTuple tuple;
RecordIOData *my_extra;
int ncolumns;
int usercols;
int validcols;
int i;
Datum *values;
bool *nulls;
/*
* Use the passed type unless it's RECORD; we can't support input of
* anonymous types, mainly because there's no good way to figure out which
* anonymous type is wanted. Note that for RECORD, what we'll probably
* actually get is RECORD's typelem, ie, zero.
*/
if (tupType == InvalidOid || tupType == RECORDOID)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("input of anonymous composite types is not implemented")));
tupTypmod = -1; /* for all non-anonymous types */
tupdesc = lookup_rowtype_tupdesc(tupType, tupTypmod);
ncolumns = tupdesc->natts;
/*
* We arrange to look up the needed I/O info just once per series of
* calls, assuming the record type doesn't change underneath us.
*/
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
if (my_extra == NULL ||
my_extra->ncolumns != ncolumns)
{
fcinfo->flinfo->fn_extra =
MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
sizeof(RecordIOData) - sizeof(ColumnIOData)
+ ncolumns * sizeof(ColumnIOData));
my_extra = (RecordIOData *) fcinfo->flinfo->fn_extra;
my_extra->record_type = InvalidOid;
my_extra->record_typmod = 0;
}
if (my_extra->record_type != tupType ||
my_extra->record_typmod != tupTypmod)
{
MemSet(my_extra, 0,
sizeof(RecordIOData) - sizeof(ColumnIOData)
+ ncolumns * sizeof(ColumnIOData));
my_extra->record_type = tupType;
my_extra->record_typmod = tupTypmod;
my_extra->ncolumns = ncolumns;
}
values = (Datum *) palloc(ncolumns * sizeof(Datum));
nulls = (bool *) palloc(ncolumns * sizeof(bool));
/* Fetch number of columns user thinks it has */
usercols = pq_getmsgint(buf, 4);
/* Need to scan to count nondeleted columns */
validcols = 0;
for (i = 0; i < ncolumns; i++)
{
if (!tupdesc->attrs[i]->attisdropped)
validcols++;
}
if (usercols != validcols)
ereport(ERROR,
(errcode(ERRCODE_DATATYPE_MISMATCH),
errmsg("wrong number of columns: %d, expected %d",
usercols, validcols)));
/* Process each column */
for (i = 0; i < ncolumns; i++)
{
ColumnIOData *column_info = &my_extra->columns[i];
Oid column_type = tupdesc->attrs[i]->atttypid;
Oid coltypoid;
int itemlen;
StringInfoData item_buf;
StringInfo bufptr;
char csave;
/* Ignore dropped columns in datatype, but fill with nulls */
if (tupdesc->attrs[i]->attisdropped)
{
values[i] = (Datum) 0;
//.........这里部分代码省略.........
示例5: geography_as_gml
Datum geography_as_gml(PG_FUNCTION_ARGS)
{
LWGEOM *lwgeom = NULL;
GSERIALIZED *g = NULL;
char *gml;
text *result;
int version;
char *srs;
int srid = SRID_DEFAULT;
int precision = OUT_MAX_DOUBLE_PRECISION;
int option=0;
int lwopts = LW_GML_IS_DIMS;
static const char *default_prefix = "gml:";
char *prefixbuf;
const char* prefix = default_prefix;
text *prefix_text;
/* Get the version */
version = PG_GETARG_INT32(0);
if ( version != 2 && version != 3 )
{
elog(ERROR, "Only GML 2 and GML 3 are supported");
PG_RETURN_NULL();
}
/* Get the geography */
if ( PG_ARGISNULL(1) ) PG_RETURN_NULL();
g = (GSERIALIZED*)PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
/* Convert to lwgeom so we can run the old functions */
lwgeom = lwgeom_from_gserialized(g);
/* Retrieve precision if any (default is max) */
if (PG_NARGS() >2 && !PG_ARGISNULL(2))
{
precision = PG_GETARG_INT32(2);
if ( precision > OUT_MAX_DOUBLE_PRECISION )
precision = OUT_MAX_DOUBLE_PRECISION;
else if ( precision < 0 ) precision = 0;
}
/* retrieve option */
if (PG_NARGS() >3 && !PG_ARGISNULL(3))
option = PG_GETARG_INT32(3);
/* retrieve prefix */
if (PG_NARGS() >4 && !PG_ARGISNULL(4))
{
prefix_text = PG_GETARG_TEXT_P(4);
if ( VARSIZE(prefix_text)-VARHDRSZ == 0 )
{
prefix = "";
}
else
{
/* +2 is one for the ':' and one for term null */
prefixbuf = palloc(VARSIZE(prefix_text)-VARHDRSZ+2);
memcpy(prefixbuf, VARDATA(prefix_text),
VARSIZE(prefix_text)-VARHDRSZ);
/* add colon and null terminate */
prefixbuf[VARSIZE(prefix_text)-VARHDRSZ] = ':';
prefixbuf[VARSIZE(prefix_text)-VARHDRSZ+1] = '\0';
prefix = prefixbuf;
}
}
if (option & 1) srs = getSRSbySRID(srid, false);
else srs = getSRSbySRID(srid, true);
if (!srs)
{
elog(ERROR, "SRID %d unknown in spatial_ref_sys table", SRID_DEFAULT);
PG_RETURN_NULL();
}
/* Revert lat/lon only with long SRS */
if (option & 1) lwopts |= LW_GML_IS_DEGREE;
if (option & 2) lwopts &= ~LW_GML_IS_DIMS;
if (version == 2)
gml = lwgeom_to_gml2(lwgeom, srs, precision, prefix);
else
gml = lwgeom_to_gml3(lwgeom, srs, precision, lwopts, prefix);
lwgeom_free(lwgeom);
PG_FREE_IF_COPY(g, 1);
/* Return null on null */
if ( ! gml )
PG_RETURN_NULL();
/* Turn string result into text for return */
result = cstring2text(gml);
lwfree(gml);
PG_RETURN_TEXT_P(result);
}
示例6: pgfadvise
Datum
pgfadvise(PG_FUNCTION_ARGS)
{
/* SRF Stuff */
FuncCallContext *funcctx;
pgfadvise_fctx *fctx;
/* our structure use to return values */
pgfadviseStruct *pgfdv;
/* our return value, 0 for success */
int result;
/* The file we are working on */
char filename[MAXPGPATH];
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
{
MemoryContext oldcontext;
Oid relOid = PG_GETARG_OID(0);
text *forkName = PG_GETARG_TEXT_P(1);
int advice = PG_GETARG_INT32(2);
/*
* Postgresql stuff to return a tuple
*/
TupleDesc tupdesc;
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/*
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
fctx = (pgfadvise_fctx *) palloc(sizeof(pgfadvise_fctx));
/* Build a tuple descriptor for our result type */
if (get_call_result_type(fcinfo, NULL, &tupdesc) != TYPEFUNC_COMPOSITE)
elog(ERROR, "pgfadvise: return type must be a row type");
/* provide the tuple descriptor to the fonction structure */
fctx->tupd = tupdesc;
/* open the current relation, accessShareLock */
// TODO use try_relation_open instead ?
fctx->rel = relation_open(relOid, AccessShareLock);
/* we get the common part of the filename of each segment of a relation */
fctx->relationpath = relpathpg(fctx->rel, forkName);
/* Here we keep track of current action in all calls */
fctx->advice = advice;
/* segcount is used to get the next segment of the current relation */
fctx->segcount = 0;
/* And finally we keep track of our initialization */
elog(DEBUG1, "pgfadvise: init done for %s, in fork %s",
fctx->relationpath, text_to_cstring(forkName));
funcctx->user_fctx = fctx;
MemoryContextSwitchTo(oldcontext);
}
/* After the first call, we recover our context */
funcctx = SRF_PERCALL_SETUP();
fctx = funcctx->user_fctx;
/*
* If we are still looking the first segment
* relationpath should not be suffixed
*/
if (fctx->segcount == 0)
snprintf(filename,
MAXPGPATH,
"%s",
fctx->relationpath);
else
snprintf(filename,
MAXPGPATH,
"%s.%u",
fctx->relationpath,
fctx->segcount);
elog(DEBUG1, "pgfadvise: about to work with %s, current advice : %d",
filename, fctx->advice);
/*
* Call posix_fadvise with the advice, returning the structure
*/
pgfdv = (pgfadviseStruct *) palloc(sizeof(pgfadviseStruct));
result = pgfadvise_file(filename, fctx->advice, pgfdv);
/*
* When we have work with all segments of the current relation
* We exit from the SRF
//.........这里部分代码省略.........
示例7: table_log_restore_table
//.........这里部分代码省略.........
}
if (PG_ARGISNULL(2)) {
elog(ERROR, "table_log_restore_table: missing log table name");
}
if (PG_ARGISNULL(3)) {
elog(ERROR, "table_log_restore_table: missing primary key name for log table");
}
if (PG_ARGISNULL(4)) {
elog(ERROR, "table_log_restore_table: missing copy table name");
}
if (PG_ARGISNULL(5)) {
elog(ERROR, "table_log_restore_table: missing timestamp");
}
/* first check number arguments to avoid an segfault */
if (PG_NARGS() >= 7) {
/* if argument is given, check if not null */
if (!PG_ARGISNULL(6)) {
/* yes, fetch it */
search_pkey = __table_log_varcharout((VarChar *)PG_GETARG_VARCHAR_P(6));
/* and check, if we have an argument */
if (strlen(search_pkey) > 0) {
need_search_pkey = 1;
#ifdef TABLE_LOG_DEBUG
elog(NOTICE, "table_log_restore_table: will restore a single key");
#endif /* TABLE_LOG_DEBUG */
}
}
}
/* same procedere here */
if (PG_NARGS() >= 8) {
if (!PG_ARGISNULL(7)) {
method = PG_GETARG_INT32(7);
if (method > 0) {
method = 1;
} else {
method = 0;
}
}
}
#ifdef TABLE_LOG_DEBUG
if (method == 1) {
elog(NOTICE, "table_log_restore_table: will restore from actual state backwards");
} else {
elog(NOTICE, "table_log_restore_table: will restore from begin forward");
}
#endif /* TABLE_LOG_DEBUG */
if (PG_NARGS() >= 9) {
if (!PG_ARGISNULL(8)) {
not_temporarly = PG_GETARG_INT32(8);
if (not_temporarly > 0) {
not_temporarly = 1;
} else {
not_temporarly = 0;
}
}
}
#ifdef TABLE_LOG_DEBUG
if (not_temporarly == 1) {
elog(NOTICE, "table_log_restore_table: dont create restore table temporarly");
}
#endif /* TABLE_LOG_DEBUG */
/* get parameter */
table_orig = __table_log_varcharout((VarChar *)PG_GETARG_VARCHAR_P(0));
table_orig_pkey = __table_log_varcharout((VarChar *)PG_GETARG_VARCHAR_P(1));
示例8: gin_trgm_triconsistent
/*
* In all cases, GIN_TRUE is at least as favorable to inclusion as
* GIN_MAYBE. If no better option is available, simply treat
* GIN_MAYBE as if it were GIN_TRUE and apply the same test as the binary
* consistent function.
*/
Datum
gin_trgm_triconsistent(PG_FUNCTION_ARGS)
{
GinTernaryValue *check = (GinTernaryValue *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
/* text *query = PG_GETARG_TEXT_P(2); */
int32 nkeys = PG_GETARG_INT32(3);
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
GinTernaryValue res = GIN_MAYBE;
int32 i,
ntrue;
bool *boolcheck;
switch (strategy)
{
case SimilarityStrategyNumber:
/* Count the matches */
ntrue = 0;
for (i = 0; i < nkeys; i++)
{
if (check[i] != GIN_FALSE)
ntrue++;
}
/*
* See comment in gin_trgm_consistent() about * upper bound formula
*/
res = (nkeys == 0) ? GIN_FALSE : (((((float4) ntrue) / ((float4) nkeys)) >= trgm_limit) ? GIN_MAYBE : GIN_FALSE);
break;
case ILikeStrategyNumber:
#ifndef IGNORECASE
elog(ERROR, "cannot handle ~~* with case-sensitive trigrams");
#endif
/* FALL THRU */
case LikeStrategyNumber:
/* Check if all extracted trigrams are presented. */
res = GIN_MAYBE;
for (i = 0; i < nkeys; i++)
{
if (check[i] == GIN_FALSE)
{
res = GIN_FALSE;
break;
}
}
break;
case RegExpICaseStrategyNumber:
#ifndef IGNORECASE
elog(ERROR, "cannot handle ~* with case-sensitive trigrams");
#endif
/* FALL THRU */
case RegExpStrategyNumber:
if (nkeys < 1)
{
/* Regex processing gave no result: do full index scan */
res = GIN_MAYBE;
}
else
{
/*
* As trigramsMatchGraph implements a montonic boolean function,
* promoting all GIN_MAYBE keys to GIN_TRUE will give a
* conservative result.
*/
boolcheck = (bool *) palloc(sizeof(bool) * nkeys);
for (i = 0; i < nkeys; i++)
boolcheck[i] = (check[i] != GIN_FALSE);
if (!trigramsMatchGraph((TrgmPackedGraph *) extra_data[0],
boolcheck))
res = GIN_FALSE;
pfree(boolcheck);
}
break;
default:
elog(ERROR, "unrecognized strategy number: %d", strategy);
res = GIN_FALSE; /* keep compiler quiet */
break;
}
/* All cases served by this function are inexact */
Assert(res != GIN_TRUE);
PG_RETURN_GIN_TERNARY_VALUE(res);
}
示例9: generate_series_step_int4
Datum
generate_series_step_int4(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
generate_series_fctx *fctx;
int32 result;
MemoryContext oldcontext;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
{
int32 start = PG_GETARG_INT32(0);
int32 finish = PG_GETARG_INT32(1);
int32 step = 1;
/* see if we were given an explicit step size */
if (PG_NARGS() == 3)
step = PG_GETARG_INT32(2);
if (step == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("step size cannot equal zero")));
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/*
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
/*
* Use fctx to keep state from call to call. Seed current with the
* original start value
*/
fctx->current = start;
fctx->finish = finish;
fctx->step = step;
funcctx->user_fctx = fctx;
MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
/*
* get the saved state and use current as the result for this iteration
*/
fctx = funcctx->user_fctx;
result = fctx->current;
if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
(fctx->step < 0 && fctx->current >= fctx->finish))
{
/* increment current in preparation for next iteration */
fctx->current += fctx->step;
/* if next-value computation overflows, this is the final result */
if (SAMESIGN(result, fctx->step) && !SAMESIGN(result, fctx->current))
fctx->step = 0;
/* do when there is more left to send */
SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
}
else
/* do when there is no more left */
SRF_RETURN_DONE(funcctx);
}
示例10: compute_shortest_path_astar
//.........这里部分代码省略.........
return finish(SPIcode, ret);
}
PG_FUNCTION_INFO_V1(shortest_path_astar);
Datum
shortest_path_astar(PG_FUNCTION_ARGS)
{
FuncCallContext *funcctx;
int call_cntr;
int max_calls;
TupleDesc tuple_desc;
path_element_t *path = 0;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL()) {
MemoryContext oldcontext;
int path_count = 0;
int ret;
// XXX profiling messages are not thread safe
profstart(prof_total);
profstart(prof_extract);
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/* switch to memory context appropriate for multiple function calls */
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
ret = compute_shortest_path_astar(text2char(PG_GETARG_TEXT_P(0)),
PG_GETARG_INT32(1),
PG_GETARG_INT32(2),
PG_GETARG_BOOL(3),
PG_GETARG_BOOL(4),
&path, &path_count);
#ifdef DEBUG
DBG("Ret is %i", ret);
int i;
for (i = 0; i < path_count; i++) {
DBG("Step # %i vertex_id %i ", i, path[i].vertex_id);
DBG(" edge_id %i ", path[i].edge_id);
DBG(" cost %f ", path[i].cost);
}
#endif
/* total number of tuples to be returned */
DBG("Conting tuples number\n");
funcctx->max_calls = path_count;
funcctx->user_fctx = path;
DBG("Path count %i", path_count);
funcctx->tuple_desc =
BlessTupleDesc(RelationNameGetTupleDesc("pgr_costResult"));
MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
DBG("Strange stuff doing\n");
funcctx = SRF_PERCALL_SETUP();
示例11: gin_trgm_consistent
Datum
gin_trgm_consistent(PG_FUNCTION_ARGS)
{
bool *check = (bool *) PG_GETARG_POINTER(0);
StrategyNumber strategy = PG_GETARG_UINT16(1);
/* text *query = PG_GETARG_TEXT_P(2); */
int32 nkeys = PG_GETARG_INT32(3);
Pointer *extra_data = (Pointer *) PG_GETARG_POINTER(4);
bool *recheck = (bool *) PG_GETARG_POINTER(5);
bool res;
int32 i,
ntrue;
/* All cases served by this function are inexact */
*recheck = true;
switch (strategy)
{
case SimilarityStrategyNumber:
/* Count the matches */
ntrue = 0;
for (i = 0; i < nkeys; i++)
{
if (check[i])
ntrue++;
}
/*--------------------
* If DIVUNION is defined then similarity formula is:
* c / (len1 + len2 - c)
* where c is number of common trigrams and it stands as ntrue in
* this code. Here we don't know value of len2 but we can assume
* that c (ntrue) is a lower bound of len2, so upper bound of
* similarity is:
* c / (len1 + c - c) => c / len1
* If DIVUNION is not defined then similarity formula is:
* c / max(len1, len2)
* And again, c (ntrue) is a lower bound of len2, but c <= len1
* just by definition and, consequently, upper bound of
* similarity is just c / len1.
* So, independly on DIVUNION the upper bound formula is the same.
*/
res = (nkeys == 0) ? false : ((((((float4) ntrue) / ((float4) nkeys))) >= trgm_limit) ? true : false);
break;
case ILikeStrategyNumber:
#ifndef IGNORECASE
elog(ERROR, "cannot handle ~~* with case-sensitive trigrams");
#endif
/* FALL THRU */
case LikeStrategyNumber:
/* Check if all extracted trigrams are presented. */
res = true;
for (i = 0; i < nkeys; i++)
{
if (!check[i])
{
res = false;
break;
}
}
break;
case RegExpICaseStrategyNumber:
#ifndef IGNORECASE
elog(ERROR, "cannot handle ~* with case-sensitive trigrams");
#endif
/* FALL THRU */
case RegExpStrategyNumber:
if (nkeys < 1)
{
/* Regex processing gave no result: do full index scan */
res = true;
}
else
res = trigramsMatchGraph((TrgmPackedGraph *) extra_data[0],
check);
break;
default:
elog(ERROR, "unrecognized strategy number: %d", strategy);
res = false; /* keep compiler quiet */
break;
}
PG_RETURN_BOOL(res);
}
示例12: rangesel
/*
* rangesel -- restriction selectivity for range operators
*/
Datum
rangesel(PG_FUNCTION_ARGS)
{
PlannerInfo *root = (PlannerInfo *) PG_GETARG_POINTER(0);
Oid operator___ = PG_GETARG_OID(1);
List *args = (List *) PG_GETARG_POINTER(2);
int varRelid = PG_GETARG_INT32(3);
VariableStatData vardata;
Node *other;
bool varonleft;
Selectivity selec;
TypeCacheEntry *typcache = NULL;
RangeType *constrange = NULL;
/*
* If expression is not (variable op something) or (something op
* variable), then punt and return a default estimate.
*/
if (!get_restriction_variable(root, args, varRelid,
&vardata, &other, &varonleft))
PG_RETURN_FLOAT8(default_range_selectivity(operator___));
/*
* Can't do anything useful if the something is not a constant, either.
*/
if (!IsA(other, Const))
{
ReleaseVariableStats(vardata);
PG_RETURN_FLOAT8(default_range_selectivity(operator___));
}
/*
* All the range operators are strict, so we can cope with a NULL constant
* right away.
*/
if (((Const *) other)->constisnull)
{
ReleaseVariableStats(vardata);
PG_RETURN_FLOAT8(0.0);
}
/*
* If var is on the right, commute the operator___, so that we can assume the
* var is on the left in what follows.
*/
if (!varonleft)
{
/* we have other Op var, commute to make var Op other */
operator___ = get_commutator(operator___);
if (!operator___)
{
/* Use default selectivity (should we raise an error instead?) */
ReleaseVariableStats(vardata);
PG_RETURN_FLOAT8(default_range_selectivity(operator___));
}
}
/*
* OK, there's a Var and a Const we're dealing with here. We need the
* Const to be of same range type as the column, else we can't do anything
* useful. (Such cases will likely fail at runtime, but here we'd rather
* just return a default estimate.)
*
* If the operator___ is "range @> element", the constant should be of the
* element type of the range column. Convert it to a range that includes
* only that single point, so that we don't need special handling for that
* in what follows.
*/
if (operator___ == OID_RANGE_CONTAINS_ELEM_OP)
{
typcache = range_get_typcache(fcinfo, vardata.vartype);
if (((Const *) other)->consttype == typcache->rngelemtype->type_id)
{
RangeBound lower,
upper;
lower.inclusive = true;
lower.val = ((Const *) other)->constvalue;
lower.infinite = false;
lower.lower = true;
upper.inclusive = true;
upper.val = ((Const *) other)->constvalue;
upper.infinite = false;
upper.lower = false;
constrange = range_serialize(typcache, &lower, &upper, false);
}
}
else if (operator___ == OID_RANGE_ELEM_CONTAINED_OP)
{
/*
* Here, the Var is the elem, not the range. For now we just punt and
* return the default estimate. In future we could disassemble the
* range constant and apply scalarineqsel ...
*/
}
else if (((Const *) other)->consttype == vardata.vartype)
//.........这里部分代码省略.........
示例13: LWGEOM_interiorringn_polygon
Datum LWGEOM_interiorringn_polygon(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom;
int32 wanted_index;
LWCURVEPOLY *curvepoly = NULL;
LWPOLY *poly = NULL;
POINTARRAY *ring;
LWLINE *line;
LWGEOM *lwgeom;
GSERIALIZED *result;
GBOX *bbox = NULL;
int type;
POSTGIS_DEBUG(2, "LWGEOM_interierringn_polygon called.");
wanted_index = PG_GETARG_INT32(1);
if ( wanted_index < 1 )
{
/* elog(ERROR, "InteriorRingN: ring number is 1-based"); */
PG_RETURN_NULL(); /* index out of range */
}
geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
type = gserialized_get_type(geom);
if ( (type != POLYGONTYPE) && (type != CURVEPOLYTYPE) )
{
elog(ERROR, "InteriorRingN: geom is not a polygon");
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_NULL();
}
lwgeom = lwgeom_from_gserialized(geom);
if( lwgeom_is_empty(lwgeom) )
{
lwpoly_free(poly);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_NULL();
}
if ( type == POLYGONTYPE)
{
poly = lwgeom_as_lwpoly(lwgeom_from_gserialized(geom));
/* Ok, now we have a polygon. Let's see if it has enough holes */
if ( wanted_index >= poly->nrings )
{
lwpoly_free(poly);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_NULL();
}
ring = poly->rings[wanted_index];
/* COMPUTE_BBOX==TAINTING */
if ( poly->bbox )
{
bbox = lwalloc(sizeof(GBOX));
ptarray_calculate_gbox_cartesian(ring, bbox);
}
/* This is a LWLINE constructed by interior ring POINTARRAY */
line = lwline_construct(poly->srid, bbox, ring);
result = geometry_serialize((LWGEOM *)line);
lwline_release(line);
lwpoly_free(poly);
}
else
{
curvepoly = lwgeom_as_lwcurvepoly(lwgeom_from_gserialized(geom));
if (wanted_index >= curvepoly->nrings)
{
PG_FREE_IF_COPY(geom, 0);
lwgeom_release((LWGEOM *)curvepoly);
PG_RETURN_NULL();
}
result = geometry_serialize(curvepoly->rings[wanted_index]);
lwgeom_free((LWGEOM*)curvepoly);
}
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_POINTER(result);
}
示例14: array_position_common
/*
* array_position_common
* Common code for array_position and array_position_start
*
* These are separate wrappers for the sake of opr_sanity regression test.
* They are not strict so we have to test for null inputs explicitly.
*/
static Datum
array_position_common(FunctionCallInfo fcinfo)
{
ArrayType *array;
Oid collation = PG_GET_COLLATION();
Oid element_type;
Datum searched_element,
value;
bool isnull;
int position,
position_min;
bool found = false;
TypeCacheEntry *typentry;
ArrayMetaState *my_extra;
bool null_search;
ArrayIterator array_iterator;
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
array = PG_GETARG_ARRAYTYPE_P(0);
element_type = ARR_ELEMTYPE(array);
/*
* We refuse to search for elements in multi-dimensional arrays, since we
* have no good way to report the element's location in the array.
*/
if (ARR_NDIM(array) > 1)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("searching for elements in multidimensional arrays is not supported")));
if (PG_ARGISNULL(1))
{
/* fast return when the array doesn't have have nulls */
if (!array_contains_nulls(array))
PG_RETURN_NULL();
searched_element = (Datum) 0;
null_search = true;
}
else
{
searched_element = PG_GETARG_DATUM(1);
null_search = false;
}
position = (ARR_LBOUND(array))[0] - 1;
/* figure out where to start */
if (PG_NARGS() == 3)
{
if (PG_ARGISNULL(2))
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
errmsg("initial position should not be NULL")));
position_min = PG_GETARG_INT32(2);
}
else
position_min = (ARR_LBOUND(array))[0];
/*
* We arrange to look up type info for array_create_iterator only once per
* series of calls, assuming the element type doesn't change underneath us.
*/
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
if (my_extra == NULL)
{
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
sizeof(ArrayMetaState));
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
my_extra->element_type = ~element_type;
}
if (my_extra->element_type != element_type)
{
get_typlenbyvalalign(element_type,
&my_extra->typlen,
&my_extra->typbyval,
&my_extra->typalign);
typentry = lookup_type_cache(element_type, TYPECACHE_EQ_OPR_FINFO);
if (!OidIsValid(typentry->eq_opr_finfo.fn_oid))
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmsg("could not identify an equality operator for type %s",
format_type_be(element_type))));
my_extra->element_type = element_type;
fmgr_info(typentry->eq_opr_finfo.fn_oid, &my_extra->proc);
}
//.........这里部分代码省略.........
示例15: intersectsPrepared
Datum intersectsPrepared(PG_FUNCTION_ARGS)
{
#ifndef PREPARED_GEOM
elog(ERROR,"Not implemented in this version!");
PG_RETURN_NULL(); /* never get here */
#else
PG_LWGEOM * geom1;
PG_LWGEOM * geom2;
bool result;
BOX2DFLOAT4 box1, box2;
PrepGeomCache * prep_cache;
int32 key1, key2;
geom1 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
geom2 = (PG_LWGEOM *) PG_DETOAST_DATUM(PG_GETARG_DATUM(1));
key1 = PG_GETARG_INT32(2);
key2 = PG_GETARG_INT32(3);
errorIfGeometryCollection(geom1,geom2);
errorIfSRIDMismatch(pglwgeom_getSRID(geom1), pglwgeom_getSRID(geom2));
/*
* short-circuit 1: if geom2 bounding box does not overlap
* geom1 bounding box we can prematurely return FALSE.
* Do the test IFF BOUNDING BOX AVAILABLE.
*/
if ( getbox2d_p(SERIALIZED_FORM(geom1), &box1) &&
getbox2d_p(SERIALIZED_FORM(geom2), &box2) )
{
if (( box2.xmax < box1.xmin ) || ( box2.xmin > box1.xmax ) ||
( box2.ymax < box1.ymin ) || ( box2.ymin > box1.ymax ))
PG_RETURN_BOOL(FALSE);
}
prep_cache = GetPrepGeomCache( fcinfo, geom1, geom2 );
initGEOS(lwnotice, lwnotice);
if ( prep_cache && prep_cache->prepared_geom )
{
if ( prep_cache->argnum == 1 )
{
GEOSGeom g = POSTGIS2GEOS(geom2);
result = GEOSPreparedIntersects( prep_cache->prepared_geom, g);
GEOSGeom_destroy(g);
}
else
{
GEOSGeom g = POSTGIS2GEOS(geom1);
result = GEOSPreparedIntersects( prep_cache->prepared_geom, g);
GEOSGeom_destroy(g);
}
}
else
{
GEOSGeom g1 = POSTGIS2GEOS(geom1);
GEOSGeom g2 = POSTGIS2GEOS(geom2);
result = GEOSIntersects( g1, g2);
GEOSGeom_destroy(g1);
GEOSGeom_destroy(g2);
}
if (result == 2)
{
elog(ERROR,"GEOS contains() threw an error!");
PG_RETURN_NULL(); /* never get here */
}
PG_FREE_IF_COPY(geom1, 0);
PG_FREE_IF_COPY(geom2, 1);
PG_RETURN_BOOL(result);
#endif /* PREPARED_GEOM */
}