I have a custom postgres type that looks like this:
CREATE TYPE "Sensor".sensor_telemetry AS
(
sensorid character varying(50),
measurement character varying(20),
val numeric(7,3),
ts character varying(20)
);
I am trying execute a call to a postgres function that takes an array of this type as a parameter.
I am calling this function with SQLAlchemy as follows:
result = db.session.execute("""select "Sensor"."PersistTelemetryBatch"(:batch)""", batch)
where batch looks like:
{
"batch" : [
{
"sensorID" : "phSensorA.haoshiAnalogPh",
"measurement" : "ph",
"value": 8.7,
"timestamp": "2019-12-06 18:32:36"
},
{
"sensorID" : "phSensorA.haoshiAnalogPh",
"measurement" : "ph",
"value": 8.8,
"timestamp": "2019-12-06 18:39:36"
}
]
}
When running this execution, I am met with this error:
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'dict'
I'm guessing that psycopg2 is complaining about the custom type array entry as a dict, because I can supply dictionaries as parameters to other pg function executions (but these dictionaries are not contained within an array like this case). Am I correct about this?
How do I go about correctly passing an array of these objects to my pg function?
operator.itemgetter(), which iirc returns tuples of values, if given multiple keys.