Skip to content

Add support for bulk statements. #167

@giant0791

Description

@giant0791

Add support for executing statements like:

# insertmany style:
stmt = insert(students).returning(students.c.name)

result = connection.execute(
    stmt,
    [
        {"name": "Galileo Galilei", "is_active": False, "grade": "A"},
        {"name": "Isaac Newton", "is_active": False, "grade": "B"},
        {"name": "Albert Einstein", "is_active": False, "grade": "C"},
    ]
)
# new_rows contains all the new pages just added, with the coulmn values for "name" only
new_rows = result.all()
assert len(rows) == 3

# inserted_primary_keys_rows return the inserted page ids as rows

# process bulk data
stmt = (
    update(students)
    .values(is_active = False)
    .where(students.c.start_on.before(date(1999,1,1))
    .returning(students.c.name)
)

result = connection.execute(stmt)
rows = result.all()

# rows contain all the students name that were updated
# sys cols are automatically available

Metadata

Metadata

Assignees

Labels

feature requestUse this to propose new features.

Projects

Status

No status

Relationships

None yet

Development

No branches or pull requests

Issue actions