Skip to content

parse_uuid

relationalai.semantics.std.common
parse_uuid(s: StringValue) -> Expression

Parse a UUID from its string representation.

Accepts the canonical dashed form, in either case. Any other string yields null, including one that carries the right 32 hex characters with the dashes in the wrong places.

Which other spellings are accepted depends on how a Hash is rendered where the rule runs, so treat the canonical form as the only portable input. The SQL backend also takes a bare 32-character digest, because that is how it renders a Hash; the logic backend, compiling directly, does not.

This parses a UUID string. It is not a general inverse of uuid_to_string, whose argument need not be a UUID, and whether the round trip survives depends on that rendering rather than on this function. On the SQL backend it does survive for a Hash that came from hash(...) or from a keyed entity’s identity, because that backend both renders and accepts the bare 32-character digest. Where a Hash renders any other way the same round trip yields null, so do not depend on it either way.

Parameters

  • s

    (StringValue) - The string representation of the UUID.

Returns

  • Expression - An Expression representing the parsed UUID. Returns Hash, or null if s is not one of the accepted forms.

Examples

Parse UUID from string:

select(common.parse_uuid("550e8400-e29b-41d4-a716-446655440000"))
select(common.parse_uuid(Request.session_id_str))