# bash

gcc -fPIC -I/usr/include/pgsql/server/ -c hexcast.c; gcc -shared -o hexcast.so hexcast.o;

# psql

create table if not exists "hexcast" ( "00" bytea );

create function cast_bytea_to_float8(bytea)  returns float8 as '/home/postgres/hexcast', 'cast_bytea_to_float8' language c strict;
create function cast_float8_to_bytea(float8) returns bytea  as '/home/postgres/hexcast', 'cast_float8_to_bytea' language c strict;

create cast (bytea  as float8) with function cast_bytea_to_float8(bytea ) as assignment;
create cast (float8 as bytea ) with function cast_float8_to_bytea(float8) as assignment;

copy "hexcast" ("00") from '/home/postgres/hexcast.csv.i' with delimiter ',' null 'null';
copy "hexcast" ("00") to   '/home/postgres/hexcast.csv.o' with delimiter ',' null 'null';

select "00"::float8 from hexcast;

drop cast (bytea   as float8);
drop cast (float8  as bytea );

drop function cast_bytea_to_float8;
drop function cast_float8_to_bytea;

drop table "hexcast";
