17#include "catalog/pg_type.h"
18#include "utils/uuid.h"
19#include "utils/numeric.h"
20#include "utils/fmgrprotos.h"
21#include "executor/spi.h"
22#include "access/htup_details.h"
38 char *str = PG_GETARG_CSTRING(0);
40 const unsigned toklen=
sizeof(result->
tok)-1;
49 if(strlen(str)<toklen+7 ||
50 str[0]!=
'(' || str[1]!=
' ' || str[2+toklen] !=
' ' || str[2+toklen+1] !=
','
51 || str[2+toklen+2] !=
' ' || str[strlen(str)-2] !=
' '
52 || str[strlen(str)-1] !=
')')
54 (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
55 errmsg(
"invalid input syntax for agg_token: \"%s\"",
58 strncpy(result->
tok, str+2, toklen);
59 result->
tok[toklen]=
'\0';
61 vallen=strlen(str)-toklen-2-3-2;
62 if(vallen>=
sizeof(result->
val))
63 vallen=
sizeof(result->
val)-1;
64 strncpy(result->
val, str+2+toklen+3, vallen);
65 result->
val[vallen]=
'\0';
67 PG_RETURN_POINTER(result);
93 result = psprintf(
"%s", aggtok->
tok);
95 result = psprintf(
"%s (*)", aggtok->
val);
97 PG_RETURN_CSTRING(result);
116 result = psprintf(
"%s", aggtok->
tok);
117 len = strlen(result);
119 txt_result = (text *) palloc(len + ((int32)
sizeof(int32)));
121 SET_VARSIZE(txt_result, len + ((int32)
sizeof(int32)));
122 memcpy(VARDATA(txt_result), result, len);
124 PG_RETURN_TEXT_P(txt_result);
140 provsql_warning(
"converting agg_token to numeric: provenance information is lost");
142 result = DirectFunctionCall3(numeric_in,
143 CStringGetDatum(aggtok->
val),
144 ObjectIdGetDatum(InvalidOid),
146 PG_RETURN_DATUM(result);
162 provsql_warning(
"converting agg_token to double precision: provenance information is lost");
164 result = DirectFunctionCall1(float8in,
165 CStringGetDatum(aggtok->
val));
166 PG_RETURN_DATUM(result);
182 provsql_warning(
"converting agg_token to integer: provenance information is lost");
184 result = DirectFunctionCall1(int4in,
185 CStringGetDatum(aggtok->
val));
186 PG_RETURN_DATUM(result);
202 provsql_warning(
"converting agg_token to bigint: provenance information is lost");
204 result = DirectFunctionCall1(int8in,
205 CStringGetDatum(aggtok->
val));
206 PG_RETURN_DATUM(result);
225 provsql_warning(
"converting agg_token to text: provenance information is lost");
227 len = strlen(aggtok->
val);
228 txt_result = (text *) palloc(len + VARHDRSZ);
229 SET_VARSIZE(txt_result, len + VARHDRSZ);
230 memcpy(VARDATA(txt_result), aggtok->
val, len);
232 PG_RETURN_TEXT_P(txt_result);
Datum agg_token_to_numeric(PG_FUNCTION_ARGS)
Cast an agg_token to numeric, extracting only the value.
Datum agg_token_out(PG_FUNCTION_ARGS)
Produce a display string for an agg_token.
Datum agg_token_cast(PG_FUNCTION_ARGS)
Cast an agg_token to text, returning only the UUID part.
Datum agg_token_to_int4(PG_FUNCTION_ARGS)
Cast an agg_token to integer, extracting only the value.
Datum agg_token_to_int8(PG_FUNCTION_ARGS)
Cast an agg_token to bigint, extracting only the value.
Datum agg_token_to_text(PG_FUNCTION_ARGS)
Cast an agg_token to text, extracting only the value.
Datum agg_token_to_float8(PG_FUNCTION_ARGS)
Cast an agg_token to double precision, extracting only the value.
Datum agg_token_in(PG_FUNCTION_ARGS)
Parse an agg_token value from its text representation.
Aggregate-provenance token type used in SQL aggregate functions.
bool provsql_aggtoken_text_as_uuid
When true, agg_token::text emits the underlying provenance UUID instead of "value (*)".
#define provsql_warning(fmt,...)
Emit a ProvSQL warning message (execution continues).
Core types, constants, and utilities shared across ProvSQL.
Aggregate token bundling a provenance UUID with a running value.
char val[80]
Aggregate running value as a text string.
char tok[2 *UUID_LEN+5]
Provenance UUID as a text string.