0

I get the following error when attempting use func.sum in my SQL Alchemy query:

ProgrammingError: (ProgrammingError) function sum(character varying) does not exist LINE 1: SELECT airs.trip_type AS trip_type, sum(airs.total_including... ^ HINT: No function matches the given name and argument types. You might need to add explicit type casts. 'SELECT airs.trip_type AS trip_type, sum(airs.total_including_tax) AS total \nFROM airs GROUP BY airs.trip_type' {}

CODE:

model.py
from datetime import datetime
import hashlib
from sqlalchemy.inspection import _self_inspects
from werkzeug.security import generate_password_hash, check_password_hash
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from markdown import markdown
import bleach
from flask import current_app, request, url_for
from flask.ext.login import UserMixin, AnonymousUserMixin
from app.exceptions import ValidationError
from . import db, login_manager

class Air(db.Model):
    __tablename__ = 'airs'
    id = db.Column(db.Integer, primary_key=True)
    booking_reference = db.Column(db.Integer) #, unique=True)
    company_name = db.Column(db.Unicode)
    trip_type = db.Column(db.Unicode)
    total_including_tax = db.Column(db.Unicode)

importer.py
    query =    db.session.query(Air.trip_type.label('trip_type'), func.sum(Air.total_including_tax).label("total")).group_by(Air.trip_type)
tourdownunder
  • 1,779
  • 4
  • 22
  • 34
  • 3
    The error message would suggest that `Air.total_including_tax` is a string of some sort rather than a number, summing strings doesn't make a lot of sense in SQL. – mu is too short Jun 10 '14 at 06:37

0 Answers0