The connector converts Prism values to Python values and serializes supported Python values for statement parameters. The Prism value type sent by the server determines the Python result. See Polypheny data types for database types.
Polypheny to Python
| Prism value | Python result |
|---|---|
| Boolean | bool |
| 32-bit integer, 64-bit integer | int |
| Big decimal | decimal.Decimal, including integral decimal values |
| Float, double | float |
| Date | datetime.date |
| Time | datetime.time with millisecond precision |
| Timestamp | A timezone-aware datetime.datetime in UTC |
| String | str |
| Binary | bytes |
| Null | None |
| List | list with recursively converted elements |
| Document | dict with string keys and recursively converted values |
| Interval | polypheny.interval.IntervalMonthMilliseconds |
For SQL DECIMAL, expect Decimal. Some SQL expressions and casts also produce a Prism decimal, so use the precision and type required by your application when converting numeric results. A relational row is a list of values in column order. An MQL document is a dictionary, and its nested objects and arrays become dictionaries and lists.
Python to Polypheny
| Parameter value | Prism representation |
|---|---|
bool |
Boolean |
int |
32-bit integer or 64-bit integer when in range, then big decimal |
float |
Double |
Finite decimal.Decimal |
Big decimal |
datetime.date |
Days since the Unix epoch |
datetime.time |
Time of day. Use whole seconds for parameters in version 2.0.0. |
datetime.datetime |
Unix epoch milliseconds. A naive timestamp uses the process’s local timezone. |
str |
String |
bytes |
Binary |
None |
Null |
Nonempty list |
List with recursively serialized elements |
Use a timezone-aware timestamp, such as one constructed with datetime.timezone.utc, for consistent results across hosts. Connector 2.0.0 has a known conversion issue with fractional seconds in datetime.time parameters.
An outer tuple or list passed to execute() is a sequence of positional parameters. For a single array parameter pass a nonempty list as an element of that sequence, for example ([1, 2, 3],). A dictionary supplied as params maps parameter names to values. The parameter serializer supports neither document values nor interval values. Use a language-specific expression, such as an SQL interval literal, for those values.
Intervals
IntervalMonthMilliseconds(months, milliseconds) stores an interval as two components. Read the public months and milliseconds attributes separately. Equality compares both components, and str(value) produces a description of both.
from polypheny.interval import IntervalMonthMilliseconds
duration = IntervalMonthMilliseconds(1, 3000)
assert duration.months == 1
assert duration.milliseconds == 3000
assert duration == IntervalMonthMilliseconds(1, 3000)
print(str(duration))