for (elemno = 0; elemno < num_elems; elemno++)
{ /* *Weassigneven-numberedOIDstoallthenewenumlabels.This *tellsthecomparisonfunctionstheOIDsareinthecorrectsort *orderandcanbecompareddirectly.
*/
Oid new_oid;
do
{
new_oid = GetNewOidWithIndex(pg_enum, EnumOidIndexId,
Anum_pg_enum_oid);
} while (new_oid & 1);
oids[elemno] = new_oid;
}
/* sort them, just in case OID counter wrapped from high to low */
qsort(oids, num_elems, sizeof(Oid), oid_cmp);
/* and make the entries */
indstate = CatalogOpenIndexes(pg_enum);
/* allocate the slots to use and initialize them */
nslots = Min(num_elems,
MAX_CATALOG_MULTI_INSERT_BYTES / sizeof(FormData_pg_enum));
slot = palloc(sizeof(TupleTableSlot *) * nslots); for (int i = 0; i < nslots; i++)
slot[i] = MakeSingleTupleTableSlot(RelationGetDescr(pg_enum),
&TTSOpsHeapTuple);
/* if slots are full, insert a batch of tuples */ if (slotCount == nslots)
{
CatalogTuplesMultiInsertWithInfo(pg_enum, slot, slotCount,
indstate);
slotCount = 0;
}
elemno++;
}
/* Insert any tuples left in the buffer */ if (slotCount > 0)
CatalogTuplesMultiInsertWithInfo(pg_enum, slot, slotCount,
indstate);
/* clean up */
pfree(oids); for (int i = 0; i < nslots; i++)
ExecDropSingleTupleTableSlot(slot[i]);
CatalogCloseIndexes(indstate);
table_close(pg_enum, RowExclusiveLock);
}
/* *AddEnumLabel *Addanewlabeltotheenumset.Bydefaultitgoesat *theend,buttheusercanchoosetoplaceitbeforeor *afteranyexistingsetmember.
*/ void
AddEnumLabel(Oid enumTypeOid, constchar *newVal, constchar *neighbor, bool newValIsAfter, bool skipIfExists)
{
Relation pg_enum;
Oid newOid;
Datum values[Natts_pg_enum]; bool nulls[Natts_pg_enum];
NameData enumlabel;
HeapTuple enum_tup;
float4 newelemorder;
HeapTuple *existing;
CatCList *list; int nelems; int i;
/* check length of new label is ok */ if (strlen(newVal) > (NAMEDATALEN - 1))
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid enum label \"%s\"", newVal),
errdetail("Labels must be %d bytes or less.",
NAMEDATALEN - 1)));
/* If we have to renumber the existing members, we restart from here */
restart:
/* Get the list of existing members of the enum */
list = SearchSysCacheList1(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumTypeOid));
nelems = list->n_members;
/* Sort the existing members by enumsortorder */
existing = (HeapTuple *) palloc(nelems * sizeof(HeapTuple)); for (i = 0; i < nelems; i++)
existing[i] = &(list->members[i]->tuple);
if (neighbor == NULL)
{ /* *Putthenewlabelattheendofthelist.Nochangetoexisting *tuplesisrequired.
*/ if (nelems > 0)
{
Form_pg_enum en = (Form_pg_enum) GETSTRUCT(existing[nelems - 1]);
newelemorder = en->enumsortorder + 1;
} else
newelemorder = 1;
} else
{ /* BEFORE or AFTER was specified */ int nbr_index; int other_nbr_index;
Form_pg_enum nbr_en;
Form_pg_enum other_nbr_en;
/* Locate the neighbor element */ for (nbr_index = 0; nbr_index < nelems; nbr_index++)
{
Form_pg_enum en = (Form_pg_enum) GETSTRUCT(existing[nbr_index]);
if (strcmp(NameStr(en->enumlabel), neighbor) == 0) break;
} if (nbr_index >= nelems)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"%s\" is not an existing enum label",
neighbor)));
nbr_en = (Form_pg_enum) GETSTRUCT(existing[nbr_index]);
if (midpoint == nbr_en->enumsortorder ||
midpoint == other_nbr_en->enumsortorder)
{
RenumberEnumType(pg_enum, existing, nelems); /* Clean up and start over */
pfree(existing);
ReleaseCatCacheList(list); goto restart;
}
newelemorder = midpoint;
}
}
/* Get a new OID for the new label */ if (IsBinaryUpgrade)
{ if (!OidIsValid(binary_upgrade_next_pg_enum_oid))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("pg_enum OID value not set when in binary upgrade mode")));
/* *Usebinary-upgradeoverrideforpg_enum.oid,ifsupplied.During *binaryupgrade,allpg_enum.oid'saresetthiswaysotheyare *guaranteedtobeconsistent.
*/ if (neighbor != NULL)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("ALTER TYPE ADD BEFORE/AFTER is incompatible with binary upgrade")));
/* check length of new label is ok */ if (strlen(newVal) > (NAMEDATALEN - 1))
ereport(ERROR,
(errcode(ERRCODE_INVALID_NAME),
errmsg("invalid enum label \"%s\"", newVal),
errdetail("Labels must be %d bytes or less.",
NAMEDATALEN - 1)));
/* Get the list of existing members of the enum */
list = SearchSysCacheList1(ENUMTYPOIDNAME,
ObjectIdGetDatum(enumTypeOid));
nelems = list->n_members;
/* *Locatetheelementtorenameandcheckifthenewlabelisalreadyin *use.(Theuniqueindexonpg_enumwouldcatchthatanyway,butwe *preferafriendliererrormessage.)
*/
old_tup = NULL;
found_new = false; for (i = 0; i < nelems; i++)
{
enum_tup = &(list->members[i]->tuple);
en = (Form_pg_enum) GETSTRUCT(enum_tup); if (strcmp(NameStr(en->enumlabel), oldVal) == 0)
old_tup = enum_tup; if (strcmp(NameStr(en->enumlabel), newVal) == 0)
found_new = true;
} if (!old_tup)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("\"%s\" is not an existing enum label",
oldVal))); if (found_new)
ereport(ERROR,
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("enum label \"%s\" already exists",
newVal)));
/* OK, make a writable copy of old tuple */
enum_tup = heap_copytuple(old_tup);
en = (Form_pg_enum) GETSTRUCT(enum_tup);
if (uncommitted_enum_types)
entries += hash_get_num_entries(uncommitted_enum_types); if (uncommitted_enum_values)
entries += hash_get_num_entries(uncommitted_enum_values);
/* Add two for the terminators. */ returnsizeof(Oid) * (entries + 2);
}
/* *Ifeitherlistisemptythendon'tevenbothertocreatethathash *table.Thisisthecommoncase,sincemosttransactionsdon'tcreate *oralterenums.
*/ if (OidIsValid(*serialized))
{ /* Read all the types into a new hash table. */
init_uncommitted_enum_types(); do
{
(void) hash_search(uncommitted_enum_types, serialized++,
HASH_ENTER, NULL);
} while (OidIsValid(*serialized));
}
serialized++; if (OidIsValid(*serialized))
{ /* Read all the values into a new hash table. */
init_uncommitted_enum_values(); do
{
(void) hash_search(uncommitted_enum_values, serialized++,
HASH_ENTER, NULL);
} while (OidIsValid(*serialized));
}
}
Messung V0.5 in Prozent
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.25Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 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.