python postgresql 函数

CREATE or replaceFUNCTION public.test()

    RETURNS text

AS $$

    import socket

    return socket.gethostname()

$$ LANGUAGEplpythonu;

 

CREATE or replaceFUNCTION public.test(keyword varchar)

    RETURNS numeric

AS $$

    return hash(keyword)

$$ LANGUAGEplpythonu;



CREATE or replace FUNCTION public.test(fa decimal,fb decimal,ta decimal,tb decimal)
    RETURNS decimal
AS $$
import math
frompoint = [fa,fb]
topoint = [ta,tb]


def deg2rad(d):
   return d*math.pi/180.0
def spherical_distance(f, t):
   EARTH_RADIUS_METER =6378137.0;
   flon = deg2rad(f[1])
   flat = deg2rad(f[0])
   tlon = deg2rad(t[1])
   tlat = deg2rad(t[0])
   con = math.sin(flat)*math.sin(tlat)
   con += math.cos(flat)*math.cos(tlat)*math.cos(flon - tlon)
   return round(math.acos(con)*6378137.0/1000,4)


return spherical_distance(frompoint,topoint)
$$ LANGUAGE plpythonu;

你可能感兴趣的:(python postgresql 函数)