@@ -478,45 +478,51 @@ def read_sql(
478
478
-------
479
479
DataFrame or Iterator[DataFrame]
480
480
481
+ See Also
482
+ --------
483
+ read_sql_table : Read SQL database table into a DataFrame.
484
+ read_sql_query : Read SQL query into a DataFrame.
485
+
481
486
Examples
482
487
--------
483
- Read data from SQL via either a SQL tablename or a SQL query
488
+ Read data from SQL via either a SQL query or a SQL tablename (latter not
489
+ possible for SQLite tables)
490
+ >>> from sqlite3 import connect
491
+ >>> conn = connect('file.db')
492
+ >>> df = pd.DataFrame(data=[[0, '10/11/12'], [1, '12/11/10']],
493
+ ... columns=['int_column', 'date_column'])
494
+ >>> df.to_sql('test_data', conn)
484
495
485
- >>> pd.read_sql('table_name', 'postgres:///db_name') # doctest:+SKIP
496
+ >>> pd.read_sql('SELECT * FROM test_data', con)
486
497
487
- >>> pd.read_sql('SELECT * FROM table_name', 'postgres:///db_name') # doctest:+SKIP
498
+ >>> pd.read_sql('table_name', 'postgres:///db_name') # doctest:+SKIP
488
499
489
- Apply dateparsing to columns through the " parse_dates" argument
500
+ Apply dateparsing to columns through the `` parse_dates`` argument
490
501
491
- >>> pd.read_sql('table_name ',
492
- ... 'postgres:///db_name' ,
493
- ... parse_dates=["date_column"]) # doctest:+SKIP
502
+ >>> pd.read_sql('SELECT * FROM test_data ',
503
+ ... conn ,
504
+ ... parse_dates=["date_column"])
494
505
495
- The " parse_dates" argument calls pd.to_datetime on the provided columns. Custom
496
- argument values for applying pd.to_datetime on a column are specified via a
497
- dictionary format:
506
+ The `` parse_dates`` argument calls `` pd.to_datetime`` on the provided columns.
507
+ Custom argument values for applying `` pd.to_datetime`` on a column are specified
508
+ via a dictionary format:
498
509
1. Ignore errors while parsing the values of "date_column"
499
510
500
- >>> pd.read_sql('table_name ',
501
- ... 'postgres:///db_name' ,
502
- ... parse_dates={"date_column": {"errors": "ignore"}) # doctest:+SKIP
511
+ >>> pd.read_sql('SELECT * FROM test_data ',
512
+ ... conn ,
513
+ ... parse_dates={"date_column": {"errors": "ignore"})
503
514
504
515
2. Apply a dayfirst dateparsing order on the values of "date_column"
505
516
506
- >>> pd.read_sql('table_name ',
507
- ... 'postgres:///db_name' ,
508
- ... parse_dates={"date_column": {"dayfirst": True}) # doctest:+SKIP
517
+ >>> pd.read_sql('SELECT * FROM test_data ',
518
+ ... conn ,
519
+ ... parse_dates={"date_column": {"dayfirst": True})
509
520
510
521
3. Apply custom formatting when dateparsing the values of "date_column"
511
522
512
- >>> pd.read_sql('table_name',
513
- ... 'postgres:///db_name',
514
- ... parse_dates={"date_column": {"format": "%d/%m/%Y"}) # doctest:+SKIP
515
-
516
- See Also
517
- --------
518
- read_sql_table : Read SQL database table into a DataFrame.
519
- read_sql_query : Read SQL query into a DataFrame.
523
+ >>> pd.read_sql('SELECT * FROM test_data',
524
+ ... conn,
525
+ ... parse_dates={"date_column": {"format": "%d/%m/%Y"})
520
526
"""
521
527
pandas_sql = pandasSQL_builder (con )
522
528
0 commit comments