Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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?

share|improve this question

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.