@@ -340,6 +340,71 @@ More consistent behaviour for some groupby methods:
340
340
SQL
341
341
~~~
342
342
343
+ The SQL reading and writing functions now support more database flavors
344
+ through SQLAlchemy (:issue:`2717`, :issue:`4163`, :issue:`5950`, :issue:`6292`).
345
+ All databases supported by SQLAlchemy can be used, such
346
+ as PostgreSQL, MySQL, Oracle, Microsoft SQL server (see documentation of
347
+ SQLAlchemy on `included dialects
348
+ <http://sqlalchemy.readthedocs.org/en/latest/dialects/index.html>`_).
349
+
350
+ The functionality of providing DBAPI connection objects will only be supported
351
+ for sqlite3 in the future. The ``'mysql'`` flavor is deprecated.
352
+
353
+ The new functions :func:`~pandas.read_sql_query` and :func:`~pandas.read_sql_table`
354
+ are introduced. The function :func:`~pandas.read_sql` is kept as a convenience
355
+ wrapper around the other two and will delegate to specific function depending on
356
+ the provided input (database table name or sql query).
357
+
358
+ In practice, you have to provide a SQLAlchemy ``engine`` to the sql functions.
359
+ To connect with SQLAlchemy you use the :func:`create_engine` function to create an engine
360
+ object from database URI. You only need to create the engine once per database you are
361
+ connecting to. For an in-memory sqlite database:
362
+
363
+ .. ipython:: python
364
+
365
+ from sqlalchemy import create_engine
366
+ # Create your connection.
367
+ engine = create_engine('sqlite:///:memory:')
368
+
369
+ This ``engine`` can then be used to write or read data to/from this database:
370
+
371
+ .. ipython:: python
372
+
373
+ df = pd.DataFrame({'A': [1,2,3], 'B': ['a', 'b', 'c']})
374
+ df.to_sql('db_table', engine, index=False)
375
+
376
+ You can read data from a database by specifying the table name:
377
+
378
+ .. ipython:: python
379
+
380
+ pd.read_sql_table('db_table', engine)
381
+
382
+ or by specifying a sql query:
383
+
384
+ .. ipython:: python
385
+
386
+ pd.read_sql_query('SELECT * FROM db_table', engine)
387
+
388
+ Some other enhancements to the sql functions include:
389
+
390
+ - support for writing the index. This can be controlled with the ``index``
391
+ keyword (default is True).
392
+ - specify the column label to use when writing the index with ``index_label``.
393
+ - specify string columns to parse as datetimes withh the ``parse_dates``
394
+ keyword in :func:`~pandas.read_sql_query` and :func:`~pandas.read_sql_table`.
395
+
396
+ .. warning::
397
+
398
+ Some of the existing functions or function aliases have been deprecated
399
+ and will be removed in future versions. This includes: ``tquery``, ``uquery``,
400
+ ``read_frame``, ``frame_query``, ``write_frame``.
401
+
402
+ .. warning::
403
+
404
+ The support for the 'mysql' flavor when using DBAPI connection objects has been deprecated.
405
+ MySQL will be further supported with SQLAlchemy engines (:issue:`6900`).
406
+
407
+
343
408
.. _whatsnew_0140.slicers:
344
409
345
410
MultiIndexing Using Slicers
@@ -573,6 +638,8 @@ Deprecations
573
638
- The support for the 'mysql' flavor when using DBAPI connection objects has been deprecated.
574
639
MySQL will be further supported with SQLAlchemy engines (:issue:`6900`).
575
640
641
+ - The following ``io.sql`` functions have been deprecated: ``tquery``, ``uquery``, ``read_frame``, ``frame_query``, ``write_frame``.
642
+
576
643
- The `percentile_width` keyword argument in :meth:`~DataFrame.describe` has been deprecated.
577
644
Use the `percentiles` keyword instead, which takes a list of percentiles to display. The
578
645
default output is unchanged.
0 commit comments