You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/sqlalchemy.md
+10-7Lines changed: 10 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1084,18 +1084,18 @@ CREATE TABLE orders (
1084
1084
)
1085
1085
```
1086
1086
1087
-
#### Querying ARRAY data with typed SQLAlchemy expressions
1087
+
#### Querying ARRAY data
1088
1088
1089
1089
Use `select()` with `ARRAY` or `AthenaArray` columns whose element types are known, either declared explicitly or reflected from Athena, to receive typed Python collections.
1090
1090
For example, the `events` table above returns `numbers` as a list of integers and `labels` as nested lists of strings.
1091
-
SQLAlchemy serializes these result columns as JSON in Athena and converts the returned values according to the column types.
1091
+
PyAthena projects these result columns as JSON in the generated SQL and converts the returned values according to the column types.
1092
1092
You do not need to call `json.loads()` on these results.
1093
1093
This preserves strings such as `"a,b"`, `"001"`, and `"null"` as strings, including within nested arrays.
1094
1094
1095
1095
#### Direct cursor and textual SQL results
1096
1096
1097
1097
Direct `cursor.execute()` calls and untyped SQLAlchemy `text()` queries use the cursor's existing conversion behavior.
1098
-
The examples in this section use the standard REST cursor with its default converter and no result type hints or custom converters.
1098
+
The examples in this section use a standard REST `cursor` created as in [Basic usage](usage.md#basic-usage), with its default converter and no result type hints or custom converters.
1099
1099
Other cursor implementations have their own conversion behavior.
1100
1100
1101
1101
The standard converter already converts simple ARRAY values to Python lists:
@@ -1114,19 +1114,22 @@ The following examples show its behavior for strings received as ARRAY values:
The unquoted nested string array is not valid JSON, and the native parser does not support nested arrays.
1123
-
The last example contains an equals sign that the native parser rejects.
1124
+
In the last example, `b=1` is outside a `{...}` ROW element, so the native parser rejects it.
1124
1125
For these unsupported representations, the converter returns the original string rather than dropping unparsed elements.
1125
1126
A string result therefore does not necessarily mean the stored ARRAY is invalid.
1126
1127
Calling `json.loads()` on that native text will not resolve these cases because it is not JSON.
1127
1128
1128
-
Use typed SQLAlchemy SELECT expressions when element types and nested string values must be preserved.
1129
-
When writing SQL directly, explicitly request JSON as shown below.
1129
+
A list result alone does not guarantee that the original elements were preserved.
1130
+
For example, the native text `[a,b, null]` becomes `["a", "b", None]`, which would be incorrect for an original array of two strings, `["a,b", "null"]`.
1131
+
The native representation does not distinguish commas within strings from element separators, or the string `"null"` from a NULL element.
1132
+
Use typed SQLAlchemy SELECT expressions for string elements or nested arrays, or explicitly request JSON when writing SQL directly, as shown below.
0 commit comments