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 (259) [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?