@@ -2999,7 +2999,7 @@ def to_sql(
2999
2999
3
3000
3000
>>> from sqlalchemy import text
3001
3001
>>> with engine.connect() as conn:
3002
- ... conn.execute(text("SELECT * FROM users")).fetchall()
3002
+ ... conn.execute(text("SELECT * FROM users")).fetchall()
3003
3003
[(0, 'User 1'), (1, 'User 2'), (2, 'User 3')]
3004
3004
3005
3005
An `sqlalchemy.engine.Connection` can also be passed to `con`:
@@ -3016,7 +3016,7 @@ def to_sql(
3016
3016
>>> df2.to_sql(name='users', con=engine, if_exists='append')
3017
3017
2
3018
3018
>>> with engine.connect() as conn:
3019
- ... conn.execute(text("SELECT * FROM users")).fetchall()
3019
+ ... conn.execute(text("SELECT * FROM users")).fetchall()
3020
3020
[(0, 'User 1'), (1, 'User 2'), (2, 'User 3'),
3021
3021
(0, 'User 4'), (1, 'User 5'), (0, 'User 6'),
3022
3022
(1, 'User 7')]
@@ -3027,7 +3027,7 @@ def to_sql(
3027
3027
... index_label='id')
3028
3028
2
3029
3029
>>> with engine.connect() as conn:
3030
- ... conn.execute(text("SELECT * FROM users")).fetchall()
3030
+ ... conn.execute(text("SELECT * FROM users")).fetchall()
3031
3031
[(0, 'User 6'), (1, 'User 7')]
3032
3032
3033
3033
Use ``method`` to define a callable insertion method to do nothing
@@ -3040,13 +3040,14 @@ def to_sql(
3040
3040
... stmt = insert(table.table).values(data).on_conflict_do_nothing(index_elements=["a"])
3041
3041
... result = conn.execute(stmt)
3042
3042
... return result.rowcount
3043
- >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", method=insert_on_conflict_nothing) # doctest: +SKIP
3043
+ >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", # noqa: F821
3044
+ ... method=insert_on_conflict_nothing) # doctest: +SKIP
3044
3045
0
3045
3046
3046
3047
For MySQL, a callable to update columns ``b`` and ``c`` if there's a conflict
3047
3048
on a primary key.
3048
3049
3049
- >>> from sqlalchemy.dialects.mysql import insert
3050
+ >>> from sqlalchemy.dialects.mysql import insert # noqa: F811
3050
3051
>>> def insert_on_conflict_update(table, conn, keys, data_iter):
3051
3052
... # update columns "b" and "c" on primary key conflict
3052
3053
... data = [dict(zip(keys, row)) for row in data_iter]
@@ -3057,7 +3058,8 @@ def to_sql(
3057
3058
... stmt = stmt.on_duplicate_key_update(b=stmt.inserted.b, c=stmt.inserted.c)
3058
3059
... result = conn.execute(stmt)
3059
3060
... return result.rowcount
3060
- >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", method=insert_on_conflict_update) # doctest: +SKIP
3061
+ >>> df_conflict.to_sql(name="conflict_table", con=conn, if_exists="append", # noqa: F821
3062
+ ... method=insert_on_conflict_update) # doctest: +SKIP
3061
3063
2
3062
3064
3063
3065
Specify the dtype (especially useful for integers with missing values).
@@ -3078,7 +3080,7 @@ def to_sql(
3078
3080
3
3079
3081
3080
3082
>>> with engine.connect() as conn:
3081
- ... conn.execute(text("SELECT * FROM integers")).fetchall()
3083
+ ... conn.execute(text("SELECT * FROM integers")).fetchall()
3082
3084
[(1,), (None,), (2,)]
3083
3085
""" # noqa: E501
3084
3086
from pandas .io import sql
0 commit comments