On Tue, 20 Feb 2018 05:55:47 -0800 (PST), Kyle Felipe Vieira Roberto
wrote:
> Hi guys!
> I was helping @Yjmenezes with a python code and i had a problem with
> the folow code:
>
> distancia = []
> for i in range(145, 13000, 145):
> distancia.append((float(i)/100))
> sql = """INSERT INTO linhas_paralelas(geom)
> SELECT ST_OffsetCurve(geometry,?) from paracatu;"""
> con.executesmany(sql, distancia)
> con.commit()
> con.close()
>
Hi Kyle,
I'm not a Python programmer, so I've just tested a very
simple script.
it seems that "executemany" always expects that at least
_TWO_ bindings must be specified for each row.
test #1
=========
distancia = [1.1, 2.2, 3.3)
sql = """INSERT INTO linhas_paralelas(geom)
SELECT ST_OffsetCurve(geometry,?) from paracatu;"""
con.executesmany(sql, distancia)
this fails, returning this error message:
"Incorrect number of bindigs supplied. The current statement
uses 1, and there are 3 supplied."
test #2
=========
distancia = [(1.1), (2.2), (3.3))
sql = """INSERT INTO linhas_paralelas(geom)
SELECT ST_OffsetCurve(geometry,?) from paracatu;"""
con.executesmany(sql, distancia)
same errore as above.
test #3
=========
distancia = [(None, 1.1), (None, 2.2), (None, 3.3))
sql = """INSERT INTO linhas_paralelas(id, geom)
SELECT ?, ST_OffsetCurve(geometry,?) from paracatu;"""
con.executesmany(sql, distancia)
and finally this last test nicely works; but as you
can easily notice wa are now using 2 bindings for
each row.
I strongly suspect that this odd behavior is someway
related to Python arrays, but my personal skills about
this language are too limited to say any more.
bye Sandro