pyspark.pandas.
read_sql
Read SQL query or database table into a DataFrame.
This function is a convenience wrapper around read_sql_table and read_sql_query (for backward compatibility). It will delegate to the specific function depending on the provided input. A SQL query will be routed to read_sql_query, while a database table name will be routed to read_sql_table. Note that the delegated function might have more specific notes about their functionality not listed here.
read_sql_table
read_sql_query
Note
Some database might hit the issue of Spark: SPARK-27596
SQL query to be executed or a table name.
A JDBC URI could be provided as as str.
The URI must be JDBC URI instead of Python’s database URI.
Column(s) to set as index(MultiIndex).
List of column names to select from SQL table (only used when reading a table).
All other options passed directly into Spark’s JDBC data source.
See also
Read SQL database table into a DataFrame.
Read SQL query into a DataFrame.
Examples
>>> ps.read_sql('table_name', 'jdbc:postgresql:db_name') >>> ps.read_sql('SELECT * FROM table_name', 'jdbc:postgresql:db_name')