> CREATE OR REPLACE FUNCTION GeomFromWKB(text) > RETURNS geometry as > 'select geomFromWKB($1::geometry::bytea)' > LANGUAGE 'SQL'; Why are you running the conversion twice (WKB->GEOMETRY->WKB->GEOMETRY)? CREATE OR REPLACE FUNCTION GeomFromWKB(text) RETURNS geometry as 'select ($1::geometry)' LANGUAGE 'SQL';