I want to cast the earth datatype to a json array in Postgresql (9.5).
This is what I have:
CREATE OR REPLACE FUNCTION earth_to_json (inpt earth)
RETURNS json AS $$
SELECT json_build_array(latitude(inpt), longitude(inpt))
$$ LANGUAGE SQL;
CREATE CAST (earth AS JSON) WITH FUNCTION earth_to_json(earth) AS IMPLICIT;
When executing the query above, I get the following output:
WARNING: cast will be ignored because the source data type is a domain
CREATE CAST
Query returned successfully in 47 msec.
So the earth
datatype is domain, according to the message above. I know earthdistance is based on the cube module, but I assumed the earth
datatype is a real datatype so I should be able to cast.
So if above code should work, the code below should run fine.
SELECT ll_to_earth(10.10, 30.01)::JSON
But I get the error
ERROR: cannot cast type earth to json LINE 1