本文整理汇总了C++中PG_RETURN_NULL函数的典型用法代码示例。如果您正苦于以下问题:C++ PG_RETURN_NULL函数的具体用法?C++ PG_RETURN_NULL怎么用?C++ PG_RETURN_NULL使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了PG_RETURN_NULL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: x509_get_version
Datum x509_get_version(PG_FUNCTION_ARGS) {
bytea *raw;
X509 *cert;
int version;
// check for null value.
raw = PG_GETARG_BYTEA_P(0);
if (raw == NULL || VARSIZE(raw) == VARHDRSZ) {
PG_RETURN_NULL();
}
cert = x509_from_bytea(raw);
if (cert == NULL) {
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED), errmsg(
"unable to decode X509 record")));
}
version = X509_get_version(cert);
X509_free(cert);
PG_RETURN_INT32(version);
}
示例2: pg_stat_get_backend_wait_event_type
Datum
pg_stat_get_backend_wait_event_type(PG_FUNCTION_ARGS)
{
int32 beid = PG_GETARG_INT32(0);
PgBackendStatus *beentry;
PGPROC *proc;
const char *wait_event_type;
if ((beentry = pgstat_fetch_stat_beentry(beid)) == NULL)
wait_event_type = "<backend information not available>";
else if (!has_privs_of_role(GetUserId(), beentry->st_userid))
wait_event_type = "<insufficient privilege>";
else
{
proc = BackendPidGetProc(beentry->st_procpid);
wait_event_type = pgstat_get_wait_event_type(proc->wait_event_info);
}
if (!wait_event_type)
PG_RETURN_NULL();
PG_RETURN_TEXT_P(cstring_to_text(wait_event_type));
}
示例3: fetchval
Datum
fetchval(PG_FUNCTION_ARGS)
{
HStore *hs = PG_GETARG_HS(0);
text *key = PG_GETARG_TEXT_P(1);
HEntry *entry;
text *out;
if ((entry = findkey(hs, VARDATA(key), VARSIZE(key) - VARHDRSZ)) == NULL || entry->valisnull)
{
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(key, 1);
PG_RETURN_NULL();
}
out = palloc(VARHDRSZ + entry->vallen);
memcpy(VARDATA(out), STRPTR(hs) + entry->pos + entry->keylen, entry->vallen);
SET_VARSIZE(out, VARHDRSZ + entry->vallen);
PG_FREE_IF_COPY(hs, 0);
PG_FREE_IF_COPY(key, 1);
PG_RETURN_POINTER(out);
}
示例4: lexize_bycurrent
Datum
lexize_bycurrent(PG_FUNCTION_ARGS)
{
Datum res;
SET_FUNCOID();
if (currect_dictionary_id == 0)
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("no currect dictionary"),
errhint("Execute select set_curdict().")));
res = DirectFunctionCall3(
lexize,
ObjectIdGetDatum(currect_dictionary_id),
PG_GETARG_DATUM(0),
(Datum) 0
);
if (res)
PG_RETURN_DATUM(res);
else
PG_RETURN_NULL();
}
示例5: format_type
/*
* SQL function: format_type(type_oid, typemod)
*
* `type_oid' is from pg_type.oid, `typemod' is from
* pg_attribute.atttypmod. This function will get the type name and
* format it and the modifier to canonical SQL format, if the type is
* a standard type. Otherwise you just get pg_type.typname back,
* double quoted if it contains funny characters or matches a keyword.
*
* If typemod is NULL then we are formatting a type name in a context where
* no typemod is available, eg a function argument or result type. This
* yields a slightly different result from specifying typemod = -1 in some
* cases. Given typemod = -1 we feel compelled to produce an output that
* the parser will interpret as having typemod -1, so that pg_dump will
* produce CREATE TABLE commands that recreate the original state. But
* given NULL typemod, we assume that the parser's interpretation of
* typemod doesn't matter, and so we are willing to output a slightly
* "prettier" representation of the same type. For example, type = bpchar
* and typemod = NULL gets you "character", whereas typemod = -1 gets you
* "bpchar" --- the former will be interpreted as character(1) by the
* parser, which does not yield typemod -1.
*
* XXX encoding a meaning in typemod = NULL is ugly; it'd have been
* cleaner to make two functions of one and two arguments respectively.
* Not worth changing it now, however.
*/
Datum
format_type(PG_FUNCTION_ARGS)
{
Oid type_oid;
int32 typemod;
char *result;
/* Since this function is not strict, we must test for null args */
if (PG_ARGISNULL(0))
PG_RETURN_NULL();
type_oid = PG_GETARG_OID(0);
if (PG_ARGISNULL(1))
result = format_type_internal(type_oid, -1, false, true);
else
{
typemod = PG_GETARG_INT32(1);
result = format_type_internal(type_oid, typemod, true, true);
}
PG_RETURN_TEXT_P(cstring_to_text(result));
}
示例6: LWGEOM_x_point
Datum LWGEOM_x_point(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom;
LWGEOM *lwgeom;
LWPOINT *point = NULL;
POINT2D p;
geom = (GSERIALIZED *)PG_DETOAST_DATUM(PG_GETARG_DATUM(0));
if ( gserialized_get_type(geom) != POINTTYPE )
lwerror("Argument to X() must be a point");
lwgeom = lwgeom_from_gserialized(geom);
point = lwgeom_as_lwpoint(lwgeom);
if ( lwgeom_is_empty(lwgeom) )
PG_RETURN_NULL();
getPoint2d_p(point->point, 0, &p);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_FLOAT8(p.x);
}
示例7: LWGEOM_line_desegmentize
Datum LWGEOM_line_desegmentize(PG_FUNCTION_ARGS)
{
GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0);
GSERIALIZED *ret;
LWGEOM *igeom = NULL, *ogeom = NULL;
POSTGIS_DEBUG(2, "LWGEOM_line_desegmentize.");
igeom = lwgeom_from_gserialized(geom);
ogeom = lwgeom_unstroke(igeom);
lwgeom_free(igeom);
if (ogeom == NULL)
{
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_NULL();
}
ret = geometry_serialize(ogeom);
lwgeom_free(ogeom);
PG_FREE_IF_COPY(geom, 0);
PG_RETURN_POINTER(ret);
}
示例8: hello
PGDLLEXPORT
Datum
hello( PG_FUNCTION_ARGS )
{
// variable declarations
char greet[] = "Hello, ";
text *towhom;
int greetlen;
int towhomlen;
text *greeting;
int greeting_size;
// Get arguments. If we declare our function as STRICT, then
// this check is superfluous.
if(PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
towhom = PG_GETARG_TEXT_P(0);
// Calculate string sizes.
greetlen = strlen(greet);
towhomlen = VARSIZE(towhom)-VARHDRSZ;
// Allocate memory and set data structure size.
greeting = (text *)palloc( greetlen + towhomlen );
//VARATT_SIZEP( greeting ) = greetlen + towhomlen + VARHDRSZ;//postgres 7.4
greeting_size=greetlen+towhomlen+VARHDRSZ;
SET_VARSIZE(greeting,greeting_size);
// Construct greeting string.
strncpy( VARDATA(greeting), greet, greetlen );
strncpy( VARDATA(greeting) + greetlen,
VARDATA(towhom),
towhomlen );
PG_RETURN_TEXT_P( greeting );
}
示例9: pg_read_file
/*
* Read a section of a file, returning it as text
*/
Datum
pg_read_file(PG_FUNCTION_ARGS)
{
text *filename_t = PG_GETARG_TEXT_PP(0);
int64 seek_offset = 0;
int64 bytes_to_read = -1;
bool missing_ok = false;
char *filename;
text *result;
if (!superuser())
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser to read files"))));
/* handle optional arguments */
if (PG_NARGS() >= 3)
{
seek_offset = PG_GETARG_INT64(1);
bytes_to_read = PG_GETARG_INT64(2);
if (bytes_to_read < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("requested length cannot be negative")));
}
if (PG_NARGS() >= 4)
missing_ok = PG_GETARG_BOOL(3);
filename = convert_and_check_filename(filename_t);
result = read_text_file(filename, seek_offset, bytes_to_read, missing_ok);
if (result)
PG_RETURN_TEXT_P(result);
else
PG_RETURN_NULL();
}
示例10: pcpatch_in
Datum pcpatch_in(PG_FUNCTION_ARGS)
{
char *str = PG_GETARG_CSTRING(0);
/* Datum geog_oid = PG_GETARG_OID(1); Not needed. */
uint32 typmod = 0, pcid = 0;
PCPATCH *patch;
SERIALIZED_PATCH *serpatch = NULL;
if ( (PG_NARGS()>2) && (!PG_ARGISNULL(2)) )
{
typmod = PG_GETARG_INT32(2);
pcid = pcid_from_typmod(typmod);
}
/* Empty string. */
if ( str[0] == '\0' )
{
ereport(ERROR,(errmsg("pcpatch parse error - empty string")));
}
/* Binary or text form? Let's find out. */
if ( str[0] == '0' )
{
/* Hex-encoded binary */
patch = pc_patch_from_hexwkb(str, strlen(str), fcinfo);
pcid_consistent(patch->schema->pcid, pcid);
serpatch = pc_patch_serialize(patch, NULL);
pc_patch_free(patch);
}
else
{
ereport(ERROR,(errmsg("parse error - support for text format not yet implemented")));
}
if ( serpatch ) PG_RETURN_POINTER(serpatch);
else PG_RETURN_NULL();
}
示例11: linterp_int32
Datum
linterp_int32(PG_FUNCTION_ARGS)
{
float8 y0;
float8 y1;
float8 p;
float8 r;
int32 result;
bool eq_bounds = false;
bool eq_abscissas = false;
/* Common */
p = linterp_abscissa(fcinfo, &eq_bounds, &eq_abscissas);
/* Ordinate type specific code*/
y0 = (float8)PG_GETARG_INT32(2);
y1 = (float8)PG_GETARG_INT32(4);
if ( eq_bounds )
{
if ( eq_abscissas && y0 == y1 )
r = y0;
else
PG_RETURN_NULL();
}
else
{
r = round(y0+p*(y1-y0));
if ( r < INT_MIN || r > INT_MAX )
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("value \"%f\" is out of range for type integer", r)));
}
result = (int32)r;
PG_RETURN_INT32(result);
}
示例12: xpath_string
Datum
xpath_string(PG_FUNCTION_ARGS)
{
text *document = PG_GETARG_TEXT_P(0);
text *xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
xmlChar *xpath;
int32 pathsize;
text *xpres;
xmlXPathObjectPtr res;
xpath_workspace workspace;
pathsize = VARSIZE(xpathsupp) - VARHDRSZ;
/*
* We encapsulate the supplied path with "string()" = 8 chars + 1 for NUL
* at end
*/
/* We could try casting to string using the libxml function? */
xpath = (xmlChar *) palloc(pathsize + 9);
strncpy((char *) xpath, "string(", 7);
memcpy((char *) (xpath + 7), VARDATA(xpathsupp), pathsize);
xpath[pathsize + 7] = ')';
xpath[pathsize + 8] = '\0';
res = pgxml_xpath(document, xpath, &workspace);
xpres = pgxml_result_to_text(res, NULL, NULL, NULL);
cleanup_workspace(&workspace);
pfree(xpath);
if (xpres == NULL)
PG_RETURN_NULL();
PG_RETURN_TEXT_P(xpres);
}
示例13: xpath_string
Datum
xpath_string(PG_FUNCTION_ARGS)
{
xmlChar *xpath;
int32 pathsize;
text
*xpathsupp,
*xpres;
/* PG_GETARG_TEXT_P(0) is document buffer */
xpathsupp = PG_GETARG_TEXT_P(1); /* XPath expression */
pathsize = VARSIZE(xpathsupp) - VARHDRSZ;
/*
* We encapsulate the supplied path with "string()" = 8 chars + 1 for NUL
* at end
*/
/* We could try casting to string using the libxml function? */
xpath = (xmlChar *) palloc(pathsize + 9);
memcpy((char *) (xpath + 7), VARDATA(xpathsupp), pathsize);
strncpy((char *) xpath, "string(", 7);
xpath[pathsize + 7] = ')';
xpath[pathsize + 8] = '\0';
xpres = pgxml_result_to_text(
pgxml_xpath(PG_GETARG_TEXT_P(0), xpath),
NULL, NULL, NULL);
xmlCleanupParser();
pfree(xpath);
if (xpres == NULL)
PG_RETURN_NULL();
PG_RETURN_TEXT_P(xpres);
}
示例14: pgx_complex_near
Datum
pgx_complex_near(PG_FUNCTION_ARGS) {
double re[2];
double im[2];
double p, q;
int i;
// unwrap values.
for (i = 0; i < 2; i++) {
HeapTupleHeader t = PG_GETARG_HEAPTUPLEHEADER(i);
bool isnull[2];
Datum dr = GetAttributeByName(t, "re", &isnull[0]);
Datum di = GetAttributeByName(t, "im", &isnull[1]);
// STRICT prevents the 'complex' value from being null but does
// not prevent its components from being null.
if (isnull[0] || isnull[1]) {
PG_RETURN_NULL();
}
re[i] = DatumGetFloat8(dr);
im[i] = DatumGetFloat8(di);
}
// compute distance between points, distance of points from origin.
p = hypot(re[0] - re[1], im[0] - im[1]);
q = hypot(re[0], im[0]) + hypot(re[1], im[1]);
if (q == 0) {
PG_RETURN_BOOL(1);
}
// we consider the points 'near' each other if the distance between them is small
// relative to the size of them.
PG_RETURN_BOOL(p / q < 1e-8);
}
示例15: quantile_numeric_array
Datum
quantile_numeric_array(PG_FUNCTION_ARGS)
{
int i, idx = 0;
struct_numeric * data;
Numeric * result;
CHECK_AGG_CONTEXT("quantile_numeric_array", fcinfo);
if (PG_ARGISNULL(0)) {
PG_RETURN_NULL();
}
data = (struct_numeric*)PG_GETARG_POINTER(0);
result = palloc(data->nquantiles * sizeof(Numeric));
qsort(data->elements, data->next, sizeof(Numeric), &numeric_comparator);
for (i = 0; i < data->nquantiles; i++) {
if ((data->quantiles[i] > 0) && (data->quantiles[i] < 1)) {
idx = (int)ceil(data->next * data->quantiles[i]) - 1;
} else if (data->quantiles[i] <= 0) {
idx = 0;
} else if (data->quantiles[i] >= 1) {
idx = data->next - 1;
}
result[i] = data->elements[idx];
}
return numeric_to_array(fcinfo, result, data->nquantiles);
}