Errata

Essential SQLAlchemy

Errata for Essential SQLAlchemy

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
ePub Page Insert 2.1
Chapter 2 Insert

Question on Insert and result proxy

How can i bulk insert one table data into another
I tried using result proxy to get the table data from Table A using select but unable to do a bulk insert into Table B
Thing i want to simulate is

insert into Table_B select * from Table_A -> how can this be simulated using result proxy in sqlalchemy core

Viswanath Duddukuri  Aug 03, 2022 
ePub Page Chapter 2 Aliases
Aliases example

Now suppose we want to select all the employees managed by an employee named Fred. => all employees where manager name = fred
--------------------------------
AND manager.name = 'Fred'

this and statement should have been manager.manager = 'Fred' that gives result as
The current manager of Abhiram is Nanda
The current manager of Ujwal is Nanda
The current manager of Kiran is Nanda for statement
-------
stmt = select([employee_table.c.name,employee_table.c.manager],
and_(employee_table.c.id == manager.c.id,
manager.c.manager == 'Nanda'))
data in the employees_table
data = [
{
'manager': 'Ram Prasad',
'name': 'Deepthi'
},
{
'manager': 'Nanda',
'name': 'Abhiram'
},
{
'manager': 'Nanda',
'name': 'Ujwal'
},
{
'manager': 'Nanda',
'name': 'Kiran'
}
]

Viswanath Duddukuri  Aug 06, 2022 
ePub Page 2.8
ResultProxy - 2.8

questions on result proxy
1.) can result proxy only be used once? ex: let s be a select stateme
s = select([func.count(engine_creation.cookies.c.cookie_id)
rp = engine_creation.connection.execute(s)
print(rp.fetchall()) -> returns [(11,)]
record = rp.first() -> returns None, but expect to return the same as fetchall()

Question is when a result proxy is created how many times can we use it, and if we want to reuse it how can this be done

Thanks a lot,
Viswanath,Duddukuri

Viswanath Duddukuri  Aug 03, 2022 
Printed Page 8
Figure 1-1

The crow's foot notation for Figure 1-1 is incorrect in 2 places:

a) Relationship users to orders is one-to-many, not many-to-one
b) Relationship cookies to line_items is one-to-many, not one-to-one

Anonymous  Oct 14, 2020 
10
Top of page

In the code:

PrimaryKeyConstraint('user_id', name='user_pk')

'user_pk' should be 'users_pk'

Joel Young  Aug 03, 2019 
PDF Page 14
bottom

The following text is in the beguinning of Chapter 2 "Working with Data via SQLAlchemy Core":

Let’s take a quick detour here to discuss what happens when we call the execute() method. When we are building a SQL Expression Language statement like the insert statement we’ve been using so far, it is actually creating a tree-like structure that can be quickly traversed in a descending manner. When we call the execute method, it uses the statement and any other parameters passed to compile the statement with the proper database dialect’s compiler. That compiler builds a normal parameterized SQL statement by walking down that tree. That statement is returned to the execute method, which sends the SQL statement to the database via the connection on which the method was called. The database server then executes the statement and returns the results of the operation.

This explanation is not clear for me, especially, what concerns the "tree-like structure". I illustrated it with an image. I temporarily placed the image on my Google drive.

https://drive.google.com/file/d/19bCL_d0e53tPGm3bV3cyjSnmgNIpD690/view?usp=sharing

I would appeciate very mach your answer if the image is correct and I would very much like to understand the meaning of what is said in the text.

Thank you in advance

Mikhail Smirnov  Mar 23, 2021 
PDF Page 42
Example 3-6. Catching an exception

An error occurred during execution of the SQL the statement

try:
result = connection.execute(ins)
except IntegrityError as error:
print(error.orig.message, error.params)

saying that 'IntegrityError' object has no 'message' attribute.

Instead of what is written in the book I used

print(error.orig, error.params)

and it worked with no errors.

Mikhail Smirnov  Apr 01, 2021