@@ -5012,6 +5012,18 @@ Example of a callable using PostgreSQL `COPY clause
5012
5012
from io import StringIO
5013
5013
5014
5014
def psql_insert_copy(table, conn, keys, data_iter):
5015
+ """
5016
+ Execute SQL statement inserting data
5017
+
5018
+ Parameters
5019
+ ----------
5020
+ table : pandas.io.sql.SQLTable
5021
+ conn : sqlalchemy.engine.Engine or sqlalchemy.engine.Connection
5022
+ keys : list of str
5023
+ Column names
5024
+ data_iter : generator of list
5025
+ Each item contains a list of values to be inserted
5026
+ """
5015
5027
# gets a DBAPI connection that can provide a cursor
5016
5028
dbapi_conn = conn.connection
5017
5029
with dbapi_conn.cursor() as cur:
@@ -5045,6 +5057,16 @@ table name and optionally a subset of columns to read.
5045
5057
5046
5058
pd.read_sql_table(' data' , engine)
5047
5059
5060
+ Note that pandas infers column dtypes from query outputs, and not by looking
5061
+ up data types in the physical database schema. For example, assume ``userid ``
5062
+ is an integer column in a table. Then, intuitively, ``select userid ... `` will
5063
+ return integer-valued series, while ``select cast(userid as text) ... `` will
5064
+ return object-valued (str) series. Accordingly, if the query output is empty,
5065
+ then all resulting columns will be returned as object-valued (since they are
5066
+ most general). If you foresee that your query will sometimes generate an empty
5067
+ result, you may want to explicitly typecast afterwards to ensure dtype
5068
+ integrity.
5069
+
5048
5070
You can also specify the name of the column as the ``DataFrame `` index,
5049
5071
and specify a subset of columns to be read.
5050
5072
0 commit comments