Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8089085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:17:56+00:00 2026-06-05T19:17:56+00:00

table : id (integer primary key) data (blob) I use mysql and sqlalchemy. To

  • 0

table:
id(integer primary key)
data(blob)

I use mysql and sqlalchemy.
To insert data I use:

o = Demo()
o.data = mydata
session.add(o)
session.commit()

I would like to insert to table like that:

INSERT INTO table(data) VALUES(COMPRESS(mydata))

How can I do this using sqlalchemy?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T19:17:58+00:00Added an answer on June 5, 2026 at 7:17 pm

    you can assign a SQL function to the attribute:

    from sqlalchemy import func
    object.data = func.compress(mydata)
    session.add(object)
    session.commit()
    

    Here’s an example using a more DB-agnostic lower() function:

    from sqlalchemy import *
    from sqlalchemy.orm import *
    from sqlalchemy.ext.declarative import declarative_base
    
    Base= declarative_base()
    
    class A(Base):
        __tablename__ = "a"
    
        id = Column(Integer, primary_key=True)
        data = Column(String)
    
    e = create_engine('sqlite://', echo=True)
    Base.metadata.create_all(e)
    s = Session(e)
    
    a1 = A()
    a1.data = func.lower("SomeData")
    s.add(a1)
    s.commit()
    
    assert a1.data == "somedata"
    

    you can make it automatic with @validates:

    from sqlalchemy.orm import validates
    class MyClass(Base):
        # ...
        data = Column(BLOB)
    
        @validates("data")
        def _set_data(self, key, value):
            return func.compress(value)
    

    if you want it readable in python before the flush, you’d need to memoize it locally and use a descriptor to access it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a table with id INTEGER PRIMARY KEY AUTOINCREMENT column and NAME VARCHAR
There is a table: create table table1 ( id integer primary key, user_id varchar(36),
I have the following defining a table: CREATE TABLE players(playerid INTEGER PRIMARY KEY AUTOINCREMENT
db.execSQL(CREATE TABLE + NotePad.Notes.TABLE_NAME + ( + NotePad.Notes._ID + INTEGER PRIMARY KEY, + NotePad.Notes.COLUMN_NAME_TITLE
How to add a column to the table: create table table1 (id integer primary
I have sqlite3 database with example structure and data: CREATE TABLE person(id INTEGER PRIMARY
My table definition is: CREATE TABLE Product (ProID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
Here is my current SQLite table: CREATE TABLE formula (_id INTEGER PRIMARY KEY AUTOINCREMENT,suggest_text_1
I have the following table: CREATE TABLE notes (noteId INTEGER PRIMARY KEY ASC, note,
I have days table created as follows create table days( + day_id integer primary

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.