Created
December 30, 2011 05:28
-
-
Save rdeguzman/1538064 to your computer and use it in GitHub Desktop.
Calling a python module from postgres function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CREATE FUNCTION pymax (a integer, b integer) | |
RETURNS integer | |
AS $$ | |
if a > b: | |
return a | |
return b | |
$$ LANGUAGE plpythonu; | |
SELECT pymax(1,2) #=> 2 | |
CREATE TYPE google_lon_lat AS (lon numeric, lat numeric); | |
CREATE FUNCTION google_geocode(param_address text) RETURNS | |
google_lon_lat | |
AS | |
$$ | |
from googlemaps import GoogleMaps | |
gmaps = GoogleMaps() | |
arg_lat, arg_long = gmaps.address_to_latlng(param_address) | |
return (arg_long, arg_lat) | |
$$ | |
language 'plpythonu'; | |
SELECT google_geocode('2 Birkenhead Ave, Wantirna, VIC, 3152') | |
ERROR: ImportError: No module named googlemaps | |
CONTEXT: Traceback (most recent call last): | |
PL/Python function "google_geocode", line 2, in <module> | |
from googlemaps import GoogleMaps | |
PL/Python function "google_geocode" | |
********** Error ********** | |
ERROR: ImportError: No module named googlemaps | |
SQL state: XX000 | |
Context: Traceback (most recent call last): | |
PL/Python function "google_geocode", line 2, in <module> | |
from googlemaps import GoogleMaps | |
PL/Python function "google_geocode" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/oginga/da29a1a99527dff59cf61ec687a5c963