
create or replace function as_text ( anyelement ) returns text as $$
  select $1::text;
$$ language sql strict immutable;

create or replace function uuid_v5 ( text, variadic text[] ) returns uuid as $$
  select uuid_generate_v5(uuid_generate_v5(uuid_ns_dns(), $1), $2::text);
$$ language sql strict immutable;

create or replace function hstore_take ( hstore, text[] ) returns hstore as $$ declare
  _keys text[] := array(select unnest(akeys($1)) intersect select unnest($2));
begin
  return case when $2 is null then $1 else hstore(_keys, $1->_keys) end;
end $$ language plpgsql immutable;
