@@ -3105,8 +3105,14 @@ below and the SQLAlchemy `documentation <http://docs.sqlalchemy.org/en/rel_0_9/c
31053105 # Create your connection.
31063106 engine = create_engine(' sqlite:///:memory:' )
31073107
3108+ Writing DataFrames
3109+ ~~~~~~~~~~~~~~~~~~
31083110
3111+ <<<<<<< HEAD
31093112Assuming the following data is in a DataFrame "data", we can insert it into
3113+ =======
3114+ Assuming the following data is in a DataFrame ``data ``, we can insert it into
3115+ >>>>>>> 6314e6f... ENH #4163 Tweaks to docs, avoid mutable default args, mysql tests
31103116the database using :func: `~pandas.io.sql.to_sql `.
31113117
31123118
@@ -3138,17 +3144,16 @@ the database using :func:`~pandas.io.sql.to_sql`.
31383144
31393145 data = DataFrame(d, columns = c)
31403146
3141- .. ipython :: python
3142-
3143- sql.to_sql(data, ' data' , engine)
3147+ Reading Tables
3148+ ~~~~~~~~~~~~~~
31443149
3145- You can read from the database simply by specifying a table
3146- name using the :func: ` ~pandas.io.sql.read_table ` function .
3150+ :func: ` ~pandas.io.sql.read_table ` will read a databse table given the
3151+ table name and optionally a subset of columns to read .
31473152
31483153.. note ::
31493154
3150- In order to use read_table, you MUST have the SQLAlchemy optional
3151- dependency installed.
3155+ In order to use :func: ` ~pandas.io.sql. read_table` , you ** must ** have the
3156+ SQLAlchemy optional dependency installed.
31523157
31533158.. ipython :: python
31543159
@@ -3176,11 +3181,17 @@ to pass to :func:`pandas.tseries.tools.to_datetime`.
31763181 sql.read_table(' data' , engine, parse_dates = {' Date' : ' %Y-%m-%d ' })
31773182 sql.read_table(' data' , engine, parse_dates = {' Date' : {' format' : ' %Y-%m-%d %H:%M:%S' }})
31783183
3184+
3185+ You can check if a table exists using :func: `~pandas.io.sql.has_table `
3186+
3187+ In addition, the class :class: `~pandas.io.sql.PandasSQLWithEngine ` can be
3188+ instantiated directly for more manual control over the SQL interaction.
3189+
31793190Querying
31803191~~~~~~~~
31813192
3182- You can also query using raw SQL in the :func: `~pandas.io.sql.read_sql ` function.
3183- In this case you must use valid SQL for your database.
3193+ You can query using raw SQL in the :func: `~pandas.io.sql.read_sql ` function.
3194+ In this case you must use the SQL variant appropriate for your database.
31843195When using SQLAlchemy, you can also pass SQLAlchemy Expression language constructs,
31853196which are database-agnostic.
31863197
@@ -3195,10 +3206,17 @@ Of course, you can specify a more "complex" query.
31953206 sql.read_frame(" SELECT id, Col_1, Col_2 FROM data WHERE id = 42;" , engine)
31963207
31973208
3198- There are a few other available functions:
3209+ You can also run a plain query without creating a dataframe with
3210+ :func: `~pandas.io.sql.execute `. This is useful for queries that don't return values,
3211+ such as INSERT. This is functionally equivalent to calling ``execute `` on the
3212+ SQLAlchemy engine or db connection object. Again, ou must use the SQL syntax
3213+ variant appropriate for your database.
3214+
3215+ .. code-block :: python
31993216
3200- :func: ` ~pandas.io.sql.has_table ` checks if a given table exists.
3217+ sql.execute( ' SELECT * FROM table_name ' , engine)
32013218
3219+ <<<<<<< HEAD
32023220<<<<<<< HEAD
32033221:func: `~pandas.io.sql.tquery ` returns a list of tuples corresponding to each row.
32043222
@@ -3209,6 +3227,10 @@ returning results it returns the number of related rows.
32093227
32103228In addition, the class :class: `~pandas.io.sql.PandasSQLWithEngine ` can be
32113229instantiated directly for more manual control over the SQL interaction.
3230+ =======
3231+ sql.execute('INSERT INTO table_name VALUES(?, ?, ?)', engine, params=[('id', 1, 12.2, True)])
3232+
3233+ >>>>>>> 6314e6f... ENH #4163 Tweaks to docs, avoid mutable default args, mysql tests
32123234
32133235Engine connection examples
32143236~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments