Skip to content

Commit 68c689f

Browse files
Taliikamotl
authored andcommitted
fixup! Enable RETURNING clause for sqlalchemy 2.0
1 parent f1a338f commit 68c689f

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ Changes for crate
55
Unreleased
66
==========
77

8+
- SQLAlchemy Core: Re-enable support for ``INSERT/UPDATE...RETURNING`` in
9+
SQLAlchemy 2.0 by adding the new ``insert_returning`` and ``update_returning`` flags
10+
in the CrateDB dialect.
811

912
2023/03/30 0.31.0
1013
=================

docs/by-example/sqlalchemy/advanced-querying.rst

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,13 @@ The first step is to define the table:
280280

281281
Now, let's use the returning clause on our insert to retrieve the values inserted:
282282

283-
>>> ins = insert(User).values(username='Crate', email='[email protected]').returning(User.username, User.email)
284-
>>> result = session.execute(ins)
283+
>>> stmt = insert(User).values(username='Crate', email='[email protected]').returning(User.username, User.email)
284+
>>> result = session.execute(stmt)
285285
>>> session.commit()
286286
>>> print([str(r) for r in result])
287287
["('Crate', '[email protected]')"]
288288

289-
The following ``INSERT...RETURNING`` statement was issued to the database:
289+
The following ``INSERT...RETURNING`` statement was issued to the database::
290290

291291
INSERT INTO user (id, username, email)
292292
VALUES (:id, :username, :email)
@@ -305,20 +305,20 @@ Insert a user and get the user id:
305305

306306
>>> from sqlalchemy import insert, update
307307

308-
>>> ins = insert(User).values(username='Arthur Dent', email='[email protected]').returning(User.id, User.username, User.email)
309-
>>> result = session.execute(ins)
308+
>>> stmt = insert(User).values(username='Arthur Dent', email='[email protected]').returning(User.id, User.username, User.email)
309+
>>> result = session.execute(stmt)
310310
>>> session.commit()
311311
>>> uid = [r[0] for r in result][0]
312312

313313
Now let's update the user:
314314

315-
>>> updt = update(User).where(User.id == uid).values(username='Tricia McMillan', email='[email protected]').returning(User.username, User.email)
316-
>>> res = session.execute(updt)
315+
>>> stmt = update(User).where(User.id == uid).values(username='Tricia McMillan', email='[email protected]').returning(User.username, User.email)
316+
>>> res = session.execute(stmt)
317317
>>> session.commit()
318318
>>> print([str(r) for r in res])
319319
["('Tricia McMillan', '[email protected]')"]
320320

321-
The following ``UPDATE...RETURNING`` statement was issued to the database:
321+
The following ``UPDATE...RETURNING`` statement was issued to the database::
322322

323323
UPDATE user SET username=:username, email=:email
324324
WHERE user.id = :id_1
@@ -332,5 +332,3 @@ The following ``UPDATE...RETURNING`` statement was issued to the database:
332332
333333
334334
.. _count result rows: https://docs.sqlalchemy.org/en/14/orm/tutorial.html#counting
335-
336-
UPDATE stuff SET content=:content WHERE stuff.id = :id_1 RETURNING stuff.content, stuff.status

0 commit comments

Comments
 (0)