'what does get_byte mean in postgresql
create or replace function data_to_text(data text)
returns text
AS $$
declare
raw bytea := ('\x' || replace(data,' ',''))::bytea;
pos integer := 0;
len integer;
res text := '';
begin
while (octet_length(raw) > pos) loop
len := (get_byte(raw, pos) -3) / 2;
exit when len <= 0;
if pos > 0 then
res := res || ', ';
end if;
res := res || (
select string_agg( chr(get_byte(raw, i)), '')
from generate_series(pos+1, pos+len) i
);
pos := pos + len + 1;
end loop;
return res;
end
$$ language plpgsql;
execute it: select * from data_to_text(' 0f 30 38 46 43 43 34 00');
return 08FCC4. It's the same result as hex numbers to text.
select octet_length ('\x' || replace(' 0f 30 38 46 43 43 34 00',' ','')::bytea); return 16
Even the manual already list one example I still not don't understand get_byte.chr is roughtly integer to character based on utf8.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
