/* *Checkiftheenumvalueislistedasuncommitted.Ifnot,it'ssafe, *becauseitcan'tbeshorter-livedthanitsowningtype.(This'dalso *befalseforvaluesmadebyothertransactions;buttheprevioustests *shouldhavehandledallofthose.)
*/ if (!EnumUncommitted(en->oid)) return;
/* *Theremightwellbeothertestswecoulddoheretonarrowdownthe *unsafeconditions,butfornowjustraiseanexception.
*/
ereport(ERROR,
(errcode(ERRCODE_UNSAFE_NEW_ENUM_VALUE_USAGE),
errmsg("unsafe use of new value \"%s\" of enum type %s",
NameStr(en->enumlabel),
format_type_be(en->enumtypid)),
errhint("New enum values must be committed before they can be used.")));
}
/* Basic I/O support */
Datum
enum_in(PG_FUNCTION_ARGS)
{ char *name = PG_GETARG_CSTRING(0);
Oid enumtypoid = PG_GETARG_OID(1);
Node *escontext = fcinfo->context;
Oid enumoid;
HeapTuple tup;
/* must check length to prevent Assert failure within SearchSysCache */ if (strlen(name) >= NAMEDATALEN)
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
tup = SearchSysCache2(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumtypoid),
CStringGetDatum(name)); if (!HeapTupleIsValid(tup))
ereturn(escontext, (Datum) 0,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
Datum
enum_out(PG_FUNCTION_ARGS)
{
Oid enumval = PG_GETARG_OID(0); char *result;
HeapTuple tup;
Form_pg_enum en;
tup = SearchSysCache1(ENUMOID, ObjectIdGetDatum(enumval)); if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid internal value for enum: %u",
enumval)));
en = (Form_pg_enum) GETSTRUCT(tup);
result = pstrdup(NameStr(en->enumlabel));
ReleaseSysCache(tup);
PG_RETURN_CSTRING(result);
}
/* Binary I/O support */
Datum
enum_recv(PG_FUNCTION_ARGS)
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
Oid enumtypoid = PG_GETARG_OID(1);
Oid enumoid;
HeapTuple tup; char *name; int nbytes;
name = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
/* must check length to prevent Assert failure within SearchSysCache */ if (strlen(name) >= NAMEDATALEN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
tup = SearchSysCache2(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumtypoid),
CStringGetDatum(name)); if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
errmsg("invalid input value for enum %s: \"%s\"",
format_type_be(enumtypoid),
name)));
/* check it's safe to use in SQL */
check_safe_enum_use(tup);
enumoid = ((Form_pg_enum) GETSTRUCT(tup))->oid;
ReleaseSysCache(tup);
pfree(name);
PG_RETURN_OID(enumoid);
}
Datum
enum_send(PG_FUNCTION_ARGS)
{
Oid enumval = PG_GETARG_OID(0);
StringInfoData buf;
HeapTuple tup;
Form_pg_enum en;
tup = SearchSysCache1(ENUMOID, ObjectIdGetDatum(enumval)); if (!HeapTupleIsValid(tup))
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid internal value for enum: %u",
enumval)));
en = (Form_pg_enum) GETSTRUCT(tup);
/* Equal OIDs are equal no matter what */ if (arg1 == arg2) return0;
/* Fast path: even-numbered Oids are known to compare correctly */ if ((arg1 & 1) == 0 && (arg2 & 1) == 0)
{ if (arg1 < arg2) return -1; else return1;
}
/* Locate the typcache entry for the enum type */
tcache = (TypeCacheEntry *) fcinfo->flinfo->fn_extra; if (tcache == NULL)
{
HeapTuple enum_tup;
Form_pg_enum en;
Oid typeoid;
/* Get the OID of the enum type containing arg1 */
enum_tup = SearchSysCache1(ENUMOID, ObjectIdGetDatum(arg1)); if (!HeapTupleIsValid(enum_tup))
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid internal value for enum: %u",
arg1)));
en = (Form_pg_enum) GETSTRUCT(enum_tup);
typeoid = en->enumtypid;
ReleaseSysCache(enum_tup); /* Now locate and remember the typcache entry */
tcache = lookup_type_cache(typeoid, 0);
fcinfo->flinfo->fn_extra = tcache;
}
/* The remaining comparison logic is in typcache.c */ return compare_values_of_enum(tcache, arg1, arg2);
}
Datum
enum_lt(PG_FUNCTION_ARGS)
{
Oid a = PG_GETARG_OID(0);
Oid b = PG_GETARG_OID(1);
enum_tuple = systable_getnext_ordered(enum_scan, direction); if (HeapTupleIsValid(enum_tuple))
{ /* check it's safe to use in SQL */
check_safe_enum_use(enum_tuple);
minmax = ((Form_pg_enum) GETSTRUCT(enum_tuple))->oid;
} else
{ /* should only happen with an empty enum */
minmax = InvalidOid;
}
Datum
enum_first(PG_FUNCTION_ARGS)
{
Oid enumtypoid;
Oid min;
/* *Werelyonbeingabletogetthespecificenumtypefromthecalling *expressiontree.Noticethattheactualvalueoftheargumentisn't *examinedatall;inparticularitmightbeNULL.
*/
enumtypoid = get_fn_expr_argtype(fcinfo->flinfo, 0); if (enumtypoid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine actual enum type")));
/* Get the OID using the index */
min = enum_endpoint(enumtypoid, ForwardScanDirection);
if (!OidIsValid(min))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("enum %s contains no values",
format_type_be(enumtypoid))));
PG_RETURN_OID(min);
}
Datum
enum_last(PG_FUNCTION_ARGS)
{
Oid enumtypoid;
Oid max;
/* *Werelyonbeingabletogetthespecificenumtypefromthecalling *expressiontree.Noticethattheactualvalueoftheargumentisn't *examinedatall;inparticularitmightbeNULL.
*/
enumtypoid = get_fn_expr_argtype(fcinfo->flinfo, 0); if (enumtypoid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine actual enum type")));
/* Get the OID using the index */
max = enum_endpoint(enumtypoid, BackwardScanDirection);
if (!OidIsValid(max))
ereport(ERROR,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("enum %s contains no values",
format_type_be(enumtypoid))));
PG_RETURN_OID(max);
}
/* 2-argument variant of enum_range */
Datum
enum_range_bounds(PG_FUNCTION_ARGS)
{
Oid lower;
Oid upper;
Oid enumtypoid;
if (PG_ARGISNULL(0))
lower = InvalidOid; else
lower = PG_GETARG_OID(0); if (PG_ARGISNULL(1))
upper = InvalidOid; else
upper = PG_GETARG_OID(1);
/* *Werelyonbeingabletogetthespecificenumtypefromthecalling *expressiontree.Thegenerictypemechanismshouldhaveensuredthat *bothareofthesametype.
*/
enumtypoid = get_fn_expr_argtype(fcinfo->flinfo, 0); if (enumtypoid == InvalidOid)
ereport(ERROR,
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
errmsg("could not determine actual enum type")));
/* and build the result array */ /* note this hardwires some details about the representation of Oid */
result = construct_array(elems, cnt, enumtypoid, sizeof(Oid), true, TYPALIGN_INT);
pfree(elems);
return result;
}
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet am 2026-08-08)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.