Vijay47
Vijay47

Reputation: 377

Unsigned float in sqlalchemy

How to have a unsigned float data type in python - sqlalchemy framework?

I am using Integer type, which results in a Warning: Out of range value for column 'xxxx' at row 1 cursor.execute(statement, parameters).

I am implementing the table like this :

class testTable(Base):
    __tablename__ = 'test_table'

    id = Column(Integer, primary_key=True)
    xxxx = Column(Integer, ForeignKey('another.id'))
    yyyy = Column(Integer, nullable=False)
    .
    .
    .

MySQL is the database server.

Upvotes: 2

Views: 14485

Answers (1)

bgse
bgse

Reputation: 8587

Looking at the documentation reveals there is the Float type.

from sqlalchemy import Float

(...)

class testTable(Base):
    __tablename__ = 'test_table'

    id = Column(Integer, primary_key=True)
    xxxx = Column(Integer, ForeignKey('another.id'))
    yyyy = Column(Integer, nullable=False)
    zzzz = Column(Float)

For MySQL specifics such as unsigned, refer to the respective documentation, e.g. importing the specific UPPERCASE types:

from sqlalchemy.dialects.mysql import FLOAT

You can then use these to create your Column as usual:

zzzz = Column(FLOAT(unsigned=True))

Upvotes: 10

Related Questions