I know there's some other discussion regarding Postgres arrays but this seemed to warrant a separate ticket.
Currently if I retrieve a column from Postgres of type _text
(text array), the returned metadata for the column using local-data-api looks like:
{'arrayBaseColumnType': 0, 'isAutoIncrement': False, 'isCaseSensitive': True, 'isCurrency': False, 'isSigned': False, 'label': 'container_type', 'name': 'container_type', 'nullable': 0, 'precision': 2147483647, 'scale': 0, 'schemaName': '', 'tableName': 'required_attributes', 'type': 12, 'typeName': 'text'}
Notice 'typeName' returning text
instead of _text
. When deployed on AWS, Data API returns for the same column:
{'arrayBaseColumnType': 0, 'isAutoIncrement': False, 'isCaseSensitive': True, 'isCurrency': False, 'isSigned': False, 'label': 'attributes', 'name': 'attributes', 'nullable': 1, 'precision': 2147483647, 'scale': 0, 'schemaName': '', 'tableName': 'required_attributes', 'type': 2003, 'typeName': '_text'}
Notice 'typeName' indeed reflects the Postgres type _text
.
This behavior continues with respect to the payload returned from the database, where local-data-api will return the value of the column as
{'stringValue': '{Volume}'}
where 'Volume' is the single item in the Postgres array. Meanwhile on AWS, Data API will return the following as value for the column:
{'arrayValue': {'stringValues': ['Volume']}}
Data API's awareness of Postgress arrays seems to be better during read than during write!
I'm using:
In code terms, the difference is captured in the two functions I maintain for local versus deployed Data API:
# Local Data API emulation currently returns arrays from database differently than
# AWS Data API, so let's establish at instantiation which function is doing our parsing.
def parse_array_local(field: Dict):
"""When running locally, parse string representation of array/set."""
return next(iter(field.values())).lstrip('{').rstrip('}').split(',')
def parse_array_deployed(field: Dict):
"""When running on AWS, return nicely formatted - albeit nested - list."""
return next(iter(field.values()))['stringValues']
Thank you, again. -jeff
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too