@@ -116,7 +116,6 @@ engine = create_engine(
116
116
connect_args = {
117
117
" session_properties" : {' query_max_run_time' : ' 1d' },
118
118
" client_tags" : [" tag1" , " tag2" ],
119
- " experimental_python_types" : True ,
120
119
" roles" : {" catalog1" : " role1" },
121
120
}
122
121
)
@@ -126,16 +125,14 @@ engine = create_engine(
126
125
' trino://user@localhost:8080/system?'
127
126
' session_properties={"query_max_run_time": "1d"}'
128
127
' &client_tags=["tag1", "tag2"]'
129
- ' &experimental_python_types=true'
130
128
' &roles={"catalog1": "role1"}'
131
129
)
132
130
133
131
# or using the URL factory method
134
132
engine = create_engine(URL(
135
133
host = " localhost" ,
136
134
port = 8080 ,
137
- client_tags = [" tag1" , " tag2" ],
138
- experimental_python_types = True
135
+ client_tags = [" tag1" , " tag2" ]
139
136
))
140
137
```
141
138
@@ -440,35 +437,33 @@ The transaction is created when the first SQL statement is executed.
440
437
exits the * with * context and the queries succeed, otherwise
441
438
`trino.dbapi.Connection.rollback()` will be called.
442
439
443
- # # Improved Python types
440
+ # # Legacy Primitive types
444
441
445
- If you enable the flag `experimental_python_types` , the client will convert the results of the query to the
442
+ By default , the client will convert the results of the query to the
446
443
corresponding Python types. For example, if the query returns a `DECIMAL ` column, the result will be a `Decimal` object .
444
+ If you want to disable this behaviour, set flag `legacy_primitive_types` to `True ` .
447
445
448
446
Limitations of the Python types are described in the
449
447
[Python types documentation](https:// docs.python.org/ 3 / library/ datatypes.html). These limitations will generate an
450
- exception `trino.exceptions.DataError ` if the query returns a value that cannot be converted to the corresponding Python
448
+ exception `trino.exceptions.TrinoDataError ` if the query returns a value that cannot be converted to the corresponding Python
451
449
type .
452
450
453
451
```python
454
452
import trino
455
- import pytz
456
- from datetime import datetime
457
453
458
454
conn = trino.dbapi.connect(
459
- experimental_python_types = True ,
455
+ legacy_primitive_types = True ,
460
456
...
461
457
)
462
458
463
459
cur = conn.cursor()
464
-
465
- params = datetime(2020 , 1 , 1 , 16 , 43 , 22 , 320000 , tzinfo = pytz.timezone(' America/Los_Angeles' ))
466
-
467
- cur.execute(" SELECT ?" , params = (params,))
460
+ # Negative DATE cannot be represented with Python types
461
+ # legacy_primitive_types needs to be enabled
462
+ cur.execute(" SELECT DATE '-2001-08-22'" )
468
463
rows = cur.fetchall()
469
464
470
- assert rows[0 ][0 ] == params
471
- assert cur.description[0 ][1 ] == " timestamp with time zone "
465
+ assert rows[0 ][0 ] == " -2001-08-22 "
466
+ assert cur.description[0 ][1 ] == " date "
472
467
```
473
468
474
469
# Need help?
0 commit comments