-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Perhaps you could advice some fast fix or workaround for that? I need update for many different rows with different values. Previously used bindparam for that.
import asyncio
from asyncpgsa import PG
from sqlalchemy import Table, MetaData, Column, Integer, String, bindparam, \
create_engine
metadata = MetaData()
table = Table(
'citizens',
metadata,
Column('test_id', Integer, primary_key=True),
Column('name', String, nullable=False),
)
DB_URL = 'postgresql://user:hackme@0.0.0.0/db'
async def main():
# create table
engine = create_engine(DB_URL)
metadata.create_all(engine)
# connect to db
pg = PG()
await pg.init(DB_URL)
async with pg.transaction() as conn:
# create
query = table.insert().values([
{'name': str(i)} for i in range(10)
]).returning(table)
rows = await conn.fetch(query)
# update
query = table.update().values(name=bindparam('name'))
await conn.execute(query, [
{'test_id': row['test_id'], 'name': row['name'] + '_new'}
for row in rows
])
# check
# asyncpg.exceptions.NotNullViolationError: null value in column "name" violates not-null constraint
# DETAIL: Failing row contains (31, null).
results = await conn.execute(table.select())
print(results)
asyncio.run(main())
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels