1

I want to use column_property to get a full address including street and house number in one column. The problem is that I want to combine two columns which are of different types. House number is of type Integer and street is of nummber string that's why I get following error:

sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) operator     
does not exist: text + integer
LINE 1: SELECT (address.road || ' ') + address.housenumber AS anon...

Well it works if I turn housenumber to a String column but that wouldn't be a clean way I guess.

Is there a way to cast the housenumber to a string when combining it with a column of type string into column_property?

Here is my code:

class Address(CommonColumns):
    __tablename__ = 'address'
    street = db.Column(db.String(80), nullable=False)
    housenumber = db.Column(db.Integer, nullable=False)
    fulladdress = db.column_property(street + " " + housenumber)

1 Answer 1

4

You need to do a cast:

fulladdress = db.column_property(street + " " + db.cast(housenumber, db.String))
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect, worked for me. Thanks! In my case the codesnippet was as following: fulladdress = db.column_property(street + " " + db.cast(housenumber, db.String))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.