SQLAlchemy: JSON vs. PickleType vs. raw string for serialised data
Cameron Simpson
cs at cskk.id.au
Mon Feb 28 16:52:03 EST 2022
On 28Feb2022 10:11, Loris Bennett <loris.bennett at fu-berlin.de> wrote:
>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 would use JSON, it expresses dicts well provided the dicts contain
only basic types (strings, numbers, other dicts/lists of basic types
recursively).
I have personal problems with pickle because nonPython code can't read
it.
Cheers,
Cameron Simpson <cs at cskk.id.au>
More information about the Python-list
mailing list