Datum uuid_in(PG_FUNCTION_ARGS) { char *uuid_str = PG_GETARG_CSTRING(0); pg_uuid_t *uuid; uuid = (pg_uuid_t *) palloc(sizeof(*uuid)); string_to_uuid(uuid_str, uuid); PG_RETURN_UUID_P(uuid); }
Datum pg_random_uuid(PG_FUNCTION_ARGS) { uint8 *buf = (uint8 *) palloc(UUID_LEN); /* * Generate random bits. pg_backend_random() will do here, we don't * promis UUIDs to be cryptographically random, when built with * --disable-strong-random. */ if (!pg_backend_random((char *) buf, UUID_LEN)) px_THROW_ERROR(PXE_NO_RANDOM); /* * Set magic numbers for a "version 4" (pseudorandom) UUID, see * http://tools.ietf.org/html/rfc4122#section-4.4 */ buf[6] = (buf[6] & 0x0f) | 0x40; /* "version" field */ buf[8] = (buf[8] & 0x3f) | 0x80; /* "variant" field */ PG_RETURN_UUID_P((pg_uuid_t *) buf); }