Skip to content

Commit

Permalink
Support decimal, date, time, timestamp with time zone and timestamp
Browse files Browse the repository at this point in the history
  • Loading branch information
mdesmet committed Mar 8, 2022
1 parent 4e61be8 commit 1ab53ad
Show file tree
Hide file tree
Showing 6 changed files with 519 additions and 31 deletions.
34 changes: 32 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,39 @@ The transaction is created when the first SQL statement is executed.
exits the *with* context and the queries succeed, otherwise
`trino.dbapi.Connection.rollback()` will be called.

## Development
# Improved Python types

### Getting Started With Development
If you enable the flag `experimental_python_types`, the client will convert the results of the query to the
corresponding Python types. For example, if the query returns a `DECIMAL` column, the result will be a `Decimal` object.

Limitations of the Python types are described in the
[Python types documentation](https://docs.python.org/3/library/datatypes.html). These limitations will generate an
exception `trino.exceptions.DataError` if the query returns a value that cannot be converted to the corresponding Python
type.

```python
import trino
import pytz
from datetime import datetime

conn = trino.dbapi.connect(
...
)

cur = conn.cursor(experimental_python_types=True)

params = datetime(2020, 1, 1, 16, 43, 22, 320000, tzinfo=pytz.timezone('America/Los_Angeles'))

cur.execute("SELECT ?", params=(params,))
rows = cur.fetchall()

assert rows[0][0] == params
assert cur.description[0][1] == "timestamp with time zone"
```

# Development

## Getting Started With Development

Start by forking the repository and then modify the code in your fork.

Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,14 @@
kerberos_require = ["requests_kerberos"]
sqlalchemy_require = ["sqlalchemy~=1.3"]

all_require = kerberos_require + sqlalchemy_require
all_require = ["pytz"] + kerberos_require + sqlalchemy_require

tests_require = all_require + [
# httpretty >= 1.1 duplicates requests in `httpretty.latest_requests`
# https://github.com/gabrielfalcao/HTTPretty/issues/425
"httpretty < 1.1",
"pytest",
"pytest-runner",
"pytz",
"click",
]

Expand Down
Loading

0 comments on commit 1ab53ad

Please sign in to comment.