I apologize in advance if this is poorly formatted; it's rather late for me.
Basically, I'm using Python with SQLAlchemy. I'm trying to map a class to a PostgreSQL DB table using the Object Relational Mapper, declarative style.
According to SQLAlchemy's documentation on data types, I should be able to use the type BigInteger
to represent potentially large integers in the Database, particularly since I know that PostgreSQL supports the BIGINT data type.
So, I attempt to declare my class like so:
import sqlalchemy
from sqlalchemy import Column, BigInteger, Text, Sequence, Boolean
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base()
class Account(Base):
__tablename__ = 'accounts'
__metadata__ = Base.metadata
id = Column(BigInteger, Sequence('id_seq'), unique=True, nullable=False)
email = Column(Text(32), unique=True, nullable=False)
def __init__(self, email):
self.email = email
However, when I try to use this file at all, I'm greeted with the following:
Traceback (most recent call last):
File "sqltest02.py", line 9, in <module>
from account import Account
File "/home/pdusen/prog/account.py", line 2, in <module>
from sqlalchemy import Column, BigInteger, Text, Sequence, Boolean
ImportError: cannot import name BigInteger
So, according to SQLAlchemy's documentation, the BigInteger
type exists, but according to python it does not. Is there something here I'm missing?
Thanks in advance for all answers.
SQLAlchemy is great because it provides a good connection / pooling infrastructure; a good Pythonic query building infrastructure; and then a good ORM infrastructure that is capable of complex queries and mappings (as well as some pretty stone-simple ones).
One of the key aspects of any data science workflow is the sourcing, cleaning, and storing of raw data in a form that can be used upstream. This process is commonly referred to as “Extract-Transform-Load,” or ETL for short.
If you want to view your data in a more schema-centric view (as used in SQL), use Core. If you have data for which business objects are not needed, use Core. If you view your data as business objects, use ORM. If you are building a quick prototype, use ORM.
To save as String by json. dumps(my_list) and then while retrieving just do json. loads(my_column) . But it will require you to set the data in a key-value format and seems a bit in-efficient compared to the previous solution.
This has been supported at least since SQL Alchemy 0.6. As noted in the comments the actual problem was a version that was too old.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With