I'm trying to use CUBE column type (PostgreSQL) in SQLAlchemy.
The idea is to assing lat and long to a model column (as a tuple), and then, when SQL is emitted, I want value to be translated to ll_to_earth(lat, lon) function to fill actual value in database.
So what I did so far is:
from sqlalchemy.types import UserDefinedType
from sqlalchemy import func
class Cube(UserDefinedType):
def get_col_spec(self):
return 'CUBE'
def bind_expression(self, bindvalue):
return func.ll_to_earth(bindvalue)
And now the problem is that function ll_to_earth
is accepting two paramters, lat
and lon
, but emitted SQL looks like:
ProgrammingError: (psycopg2.ProgrammingError) ERROR: function ll_to_earth(record) does not exists
[SQL: 'INSERT INTO facility (location) VALUES (ll_to_earth(%(location)s)) RETURNING facility.pk'] [parameters: {'location': (52.2170429, 21.019856)}]
How can I fix it?