awswrangler.oracle.read_sql_query

awswrangler.oracle.read_sql_query(sql: str, con: oracledb.Connection, index_col: str | list[str] | None = None, params: list[Any] | tuple[Any, ...] | dict[Any, Any] | None = None, chunksize: int | None = None, dtype: dict[str, pyarrow.lib.DataType] | None = None, safe: bool = True, timestamp_as_object: bool = False, dtype_backend: Literal['numpy_nullable', 'pyarrow'] = 'numpy_nullable') DataFrame | Iterator[DataFrame]

Return a DataFrame corresponding to the result set of the query string.

Parameters:
  • sql (str) – SQL query.

  • con (Connection) – Use oracledb.connect() to use credentials directly or wr.oracle.connect() to fetch it from the Glue Catalog.

  • index_col (str | list[str] | None) – Column(s) to set as index(MultiIndex).

  • params (list[Any] | tuple[Any, ...] | dict[Any, Any] | None) – List of parameters to pass to execute method. The syntax used to pass parameters is database driver dependent. Check your database driver documentation for which of the five syntax styles, described in PEP 249’s paramstyle, is supported.

  • chunksize (int | None) – If specified, return an iterator where chunksize is the number of rows to include in each chunk.

  • dtype (dict[str, DataType] | None) – Specifying the datatype for columns. The keys should be the column names and the values should be the PyArrow types.

  • safe (bool) – Check for overflows or other unsafe data type conversions.

  • timestamp_as_object (bool) – Cast non-nanosecond timestamps (np.datetime64) to objects.

  • dtype_backend (Literal['numpy_nullable', 'pyarrow']) –

    Which dtype_backend to use, e.g. whether a DataFrame should have NumPy arrays, nullable dtypes are used for all dtypes that have a nullable implementation when “numpy_nullable” is set, pyarrow is used for all dtypes if “pyarrow” is set.

    The dtype_backends are still experimential. The “pyarrow” backend is only supported with Pandas 2.0 or above.

Return type:

DataFrame | Iterator[DataFrame]

Returns:

Result as Pandas DataFrame(s).

Examples

Reading from Oracle Database using a Glue Catalog Connections

>>> import awswrangler as wr
>>> with wr.oracle.connect(connection="MY_GLUE_CONNECTION") as con:
...     df = wr.oracle.read_sql_query(
...         sql="SELECT * FROM test.my_table",
...         con=con,
...     )