Skip to content

Commit 1ab53ad

Browse files
committed
Support decimal, date, time, timestamp with time zone and timestamp
1 parent 4e61be8 commit 1ab53ad

File tree

6 files changed

+519
-31
lines changed

6 files changed

+519
-31
lines changed

README.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,39 @@ The transaction is created when the first SQL statement is executed.
317317
exits the *with* context and the queries succeed, otherwise
318318
`trino.dbapi.Connection.rollback()` will be called.
319319

320-
## Development
320+
# Improved Python types
321321

322-
### Getting Started With Development
322+
If you enable the flag `experimental_python_types`, the client will convert the results of the query to the
323+
corresponding Python types. For example, if the query returns a `DECIMAL` column, the result will be a `Decimal` object.
324+
325+
Limitations of the Python types are described in the
326+
[Python types documentation](https://docs.python.org/3/library/datatypes.html). These limitations will generate an
327+
exception `trino.exceptions.DataError` if the query returns a value that cannot be converted to the corresponding Python
328+
type.
329+
330+
```python
331+
import trino
332+
import pytz
333+
from datetime import datetime
334+
335+
conn = trino.dbapi.connect(
336+
...
337+
)
338+
339+
cur = conn.cursor(experimental_python_types=True)
340+
341+
params = datetime(2020, 1, 1, 16, 43, 22, 320000, tzinfo=pytz.timezone('America/Los_Angeles'))
342+
343+
cur.execute("SELECT ?", params=(params,))
344+
rows = cur.fetchall()
345+
346+
assert rows[0][0] == params
347+
assert cur.description[0][1] == "timestamp with time zone"
348+
```
349+
350+
# Development
351+
352+
## Getting Started With Development
323353

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

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,14 @@
2828
kerberos_require = ["requests_kerberos"]
2929
sqlalchemy_require = ["sqlalchemy~=1.3"]
3030

31-
all_require = kerberos_require + sqlalchemy_require
31+
all_require = ["pytz"] + kerberos_require + sqlalchemy_require
3232

3333
tests_require = all_require + [
3434
# httpretty >= 1.1 duplicates requests in `httpretty.latest_requests`
3535
# https://github.com/gabrielfalcao/HTTPretty/issues/425
3636
"httpretty < 1.1",
3737
"pytest",
3838
"pytest-runner",
39-
"pytz",
4039
"click",
4140
]
4241

0 commit comments

Comments
 (0)