create or replace function full_to_half(text) returns text as
$$
select string_agg(col, '') from
( select
case when ascii(col) >= 65281 and ascii(col) <=65374 then chr(ascii(col)-65248)
when ascii(col) = 12288 then chr(32)
else col
end AS col
from (select regexp_split_to_table($1, '') as col) t
) tt;
$$ language sql strict immutable;