The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

380960 (6) [Avatar] Offline
#1
This is listing 16.11

CREATE FUNCTION ch16.google_geocode(
param_addr text,
OUT address text, OUT lon numeric, OUT lat numeric
)
RETURNS record
AS
$$
from geopy.geocoders import GoogleV3
geoc = GoogleV3()
address,
(latitude,longitude) = geoc.geocode(param_addr)
return (address, longitude, latitude)
$$
LANGUAGE 'plpython3u';

If I try to geocode using

SELECT *
FROM ch16.google_geocode(
'1731 New Hampshire Avenue Northwest, Washington, DC 20010'
);

I get the error:

ERRORE: NameError: global name 'address' is not defined
CONTEXT: Traceback (most recent call last):
PL/Python function "google_geocode", line 4, in <module>
address,
funzione PL/Python "google_geocode"
********** Error **********

ERRORE: NameError: global name 'address' is not defined
SQL state: 38000
Context: Traceback (most recent call last):
PL/Python function "google_geocode", line 4, in <module>
address,
funzione PL/Python "google_geocode"

I suppose it should be:
[address,(latitude,longitude)] = geoc.geocode(param_addr)
regina.leo (265) [Avatar] Offline
#2
Sorry for lateness in reply. What you have looks right. Not setup to test at the moment, did that work for you?