Skip to content
This repository has been archived by the owner on May 5, 2022. It is now read-only.

Commit

Permalink
Merge pull request #38 from dungdm93/pandas-doc
Browse files Browse the repository at this point in the history
add Pandas support docs
  • Loading branch information
dungdm93 authored Nov 25, 2021
2 parents 5e7dcd5 + 69e7d2f commit 72eed3d
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ engine = create_engine(
'trino://<username>:<password>@<host>:<port>/?sessionUser=user-to-be-impersonated',
)
```

### Pandas support
```python
import pandas as pd
from pandas import DataFrame
import sqlalchemy_trino
from sqlalchemy.engine import Engine, Connection

def trino_pandas_write(engine: Engine):
df: DataFrame = pd.read_csv("tests/data/population.csv")
df.to_sql(con=engine, schema="default", name="abcxyz", method="multi", index=False)

print(df)


def trino_pandas_read(engine: Engine):
connection: Connection = engine.connect()
df = pd.read_sql("SELECT * FROM public.foobar", connection)

print(df)
```

**Note**: in `df.to_sql` following params is required:
* `index=False` because index is not supported in Trino.
* `method="multi"`: currently `method=None` (default) is not working because Trino dbapi is not support [`executemany`](https://github.com/trinodb/trino-python-client/blob/77adbc48cd5061b2c55e56225d67dd7822284b73/trino/dbapi.py#L410-L411) yet

0 comments on commit 72eed3d

Please sign in to comment.