S
Steve Holden
I'm trying to copy data from an Access database to PostgreSQL, as the
latter now appears to work well in the Windows environment. However I'm
having trouble with date columns.
The PostgreSQL table receiving the data has the following definition:
CREATE TABLE Lines (
LinID SERIAL PRIMARY KEY,
LinDate TIMESTAMP(0),
LinQty INTEGER,
LinPrdID INTEGER ,
LinPrice NUMERIC(8,2),
LinInvoice INTEGER)
Here's the problem in a nutshell:
'INSERT INTO Lines(LinID, LinDate, LinQty, LinPrdID, LinPrice,
LinInvoice) VALUES(%s, %s, %s, %s, %s, %s)'Traceback (most recent call last):
Since the date value's the only difference between the two, I deduce
it's causing the problem.
I'd rather not have to manipulate the data (in other words, I'd rather
just change the definition of the receiving table to avoid the error if
possible), as the copying operation attempts to be table-independent. It
currently reads:
for tbl, cols in d.items():
print "Copying", tbl
dsql = "DELETE FROM %s" % tbl
ocurs.execute(dsql)
isql = "SELECT %s FROM %s" % (", ".join(cols), tbl)
osql = "INSERT INTO %s(%s) VALUES(%s)" % (
tbl, ", ".join(cols), ", ".join("%s" for c in cols))
print isql, '\n', osql
icurs.execute(isql)
for row in icurs.fetchall():
ocurs.execute(osql, row)
Though until I started stepping through the data row by row the last two
lines were replaced by
ocurs.executemany(osql, icurs.fetchall())
Who can help me past this little sticking point?
regards
Steve
latter now appears to work well in the Windows environment. However I'm
having trouble with date columns.
The PostgreSQL table receiving the data has the following definition:
CREATE TABLE Lines (
LinID SERIAL PRIMARY KEY,
LinDate TIMESTAMP(0),
LinQty INTEGER,
LinPrdID INTEGER ,
LinPrice NUMERIC(8,2),
LinInvoice INTEGER)
Here's the problem in a nutshell:
'INSERT INTO Lines(LinID, LinDate, LinQty, LinPrdID, LinPrice,
LinInvoice) VALUES(%s, %s, %s, %s, %s, %s)'Traceback (most recent call last):
Since the date value's the only difference between the two, I deduce
it's causing the problem.
I'd rather not have to manipulate the data (in other words, I'd rather
just change the definition of the receiving table to avoid the error if
possible), as the copying operation attempts to be table-independent. It
currently reads:
for tbl, cols in d.items():
print "Copying", tbl
dsql = "DELETE FROM %s" % tbl
ocurs.execute(dsql)
isql = "SELECT %s FROM %s" % (", ".join(cols), tbl)
osql = "INSERT INTO %s(%s) VALUES(%s)" % (
tbl, ", ".join(cols), ", ".join("%s" for c in cols))
print isql, '\n', osql
icurs.execute(isql)
for row in icurs.fetchall():
ocurs.execute(osql, row)
Though until I started stepping through the data row by row the last two
lines were replaced by
ocurs.executemany(osql, icurs.fetchall())
Who can help me past this little sticking point?
regards
Steve