Code Monkey home page Code Monkey logo

Comments (4)

RuoCJ avatar RuoCJ commented on August 20, 2024 1

same here, it's slow insert also one row as well..这里也是一样,插入一行也很慢。

One idea I recently tried was to combine several insert statements into one, executed using execute instead of executemany

Can you post an example how you call multiple statements?

This operation is only for insert statements

sql = "INSERT INTO table_a (field1, field2, ..) VALUES {}"

values_str = create_insert_values(tlis_schp)
conn = db_pool.connection()
cursor = conn.cursor()
cursor.execute(sql, values_str or ())

def create_insert_values(data):
    values_list = []
    for record in data:
        values = []
        for item in record:
            if isinstance(item, str):
                escaped_item = item.replace("'", "''")
                values.append(f"'{escaped_item}'")
            elif item is None or (isinstance(item, float) and math.isnan(item)):
                values.append("NULL")
            elif isinstance(item, datetime.datetime):
                values.append(f"'{item}'")
            elif isinstance(item, decimal.Decimal):
                values.append(f"'{item}'")
            elif isinstance(item, decimal.Decimal):
                values.append(f"'{item}'")
            else:
                values.append(str(item))
        values_str = f"({', '.join(values)})"
        values_list.append(values_str)
    return ',  '.join(values_list)

This is a bit more cumbersome, but much faster than using executemany directly

from aiomysql.

yarodevuci avatar yarodevuci commented on August 20, 2024

same here, it's slow insert also one row as well..

from aiomysql.

RuoCJ avatar RuoCJ commented on August 20, 2024

same here, it's slow insert also one row as well..这里也是一样,插入一行也很慢。

One idea I recently tried was to combine several insert statements into one, executed using execute instead of executemany

from aiomysql.

yarodevuci avatar yarodevuci commented on August 20, 2024

same here, it's slow insert also one row as well..这里也是一样,插入一行也很慢。

One idea I recently tried was to combine several insert statements into one, executed using execute instead of executemany

Can you post an example how you call multiple statements?

from aiomysql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.