@@ -280,13 +280,13 @@ The first step is to define the table:
280280
281281Now, 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
313313Now 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