SQLAlchemy: JSON vs. PickleType vs. raw string for serialised data

Loris Bennett loris.bennett at fu-berlin.de
Mon Feb 28 04:11:06 EST 2022


Hi,

I have an SQLAlchemy class for an event:

  class UserEvent(Base):
      __tablename__ = "user_events"

      id = Column('id', Integer, primary_key=True)
      date = Column('date', Date, nullable=False)
      uid = Column('gid', String(64), ForeignKey('users.uid'), nullable=False)
      info = ??

The event may have arbitrary, but dict-like data associated with it,
which I want to add in the field 'info'.  This data never needs to be
modified, once the event has been inserted into the DB.

What type should the info field have?  JSON, PickleType, String, or
something else?

I couldn't find any really reliable sounding information about the relative
pros and cons, apart from a Reddit thread claiming that pickled dicts
are larger than dicts converted to JSON or String.

Cheers,

Loris

-- 
This signature is currently under construction.


More information about the Python-list mailing list