I cannot add a 2D integer array to Postgre using this code with SQLAlchemy:
def create_polygon(x, y, w, h):
polygon = []
polygon.append([1, 2])
return polygon
engine = create_engine('postgresql://usr:pwd@localhost:5432/db', echo=True)
meta = MetaData()
table = Table(
'table', meta,
Column('id', Integer, primary_key=True),
Column('polygon', ARRAY(Integer, dimensions=2))
)
meta.create_all(engine)
conn = engine.connect()
for line in lines:
insert = zone_by_cam.insert(
polygon = create_polygon(*line.params)
)
conn.execute(insert)
I got this error message:
Additional arguments should be named <dialectname>_<argument>, got 'polygon'
I then changed the name of polygon to postgresql_polygon (which is nowhere to be found in the docs), and have this one instead:
Argument 'postgresql_polygon' is not accepted by dialect 'postgresql' on behalf of <class 'sqlalchemy.sql.dml.Insert'>
How can I fix this? Thanks!