Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8594727
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:15:55+00:00 2026-06-12T00:15:55+00:00

I have 0 experience with postgresql and am deploying an app written in python

  • 0

I have 0 experience with postgresql and am deploying an app written in python using sqlalchemy to a server with postgres.

For development, I used an sqlite server.

Things are going pretty smoothly, but I hit a bump I don’t know how to resolve.

I have three tables that look like that

class Car(db.Model):
     id= db.Column(db.Integer, primary_key=True)
     ...

class Truck(db.Model):
     id= db.Column(db.String(32), primary_key=True)
     ...

class Vehicles(db.Model):
     id= db.Column(db.Integer, primary_key=True)
     type= db.Column(db.String) #This is either 'car' or 'truck'
     value= db.Column(db.String) #That's the car or truck id
     ...

I have a query that selects from Vehicles where type = 'car' AND value = 10
This is throwing an error:
sqlalchemy.exc.ProgrammingError: (ProgrammingError) operator does not exist: integer = character varying

So I guess this is because Car.id is an int and Vehicle.value is a string..

How to write this query in sqlalchemy? Is there a way to write it and make it compatible with my sqlite dev environment and the pgsql production?

currently it looks like that

db.session.query(Vehicle).filter(Car.id == Vehicle.value)

PS: The truck id has to be a string and the car id has to be an int. I don’t have control over that.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:15:57+00:00Added an answer on June 12, 2026 at 12:15 am

    Simply cast to a string:

    db.session.query(Vehicle).filter(str(Car.id) == Vehicle.value)
    

    if Car.id is a local variable that is an int.

    If you need to use this in a join, have the database cast it to a string:

    from sqlalchemy.sql.expression import cast
    
    db.session.query(Vehicle).filter(cast(Car.id, sqlalchemy.String) == Vehicle.value)
    

    If the string value in the other column contains digits and possibly whitespace you may have to consider trimming, or instead casting the string value to an integer (and leave the integer column an integer).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Anyone have experience playing audio (right now specifically mp3s) with python using a any
Does anyone have experience of using PostgreSQL for an OLAP setup, using cubes against
I have experience developing in android and using REST services, but now I'd like
Does anybody have experience build app with PhoneGap's Build Service? I followed the steps
hoping someone has experience with both sql server and postgresql. Between the two db's,
Does anyone have real world experience running a Sqlite database on an SMB share
I have a single page app (Rails + Backbone.js + Postgres on Heroku), and
I'm totally newbie with postgresql but I have a good experience with mysql. I
I have 6 months of Rails development experience. I've built a web application that's
I am using PostgreSQL data server through VB.NET/ODBC on windows what seem's pretty reliable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.