I am writing a query inside a Python script.The query is as follows:
cur = conn.cursor()
query1 = """select max(date_time) from tablename"""
cur.execute(queryy1)
conn.commit()
rows = cur.fetchall()
print rows
Until here the code works fine and gives me the date in some format of the kind datetime.datetime[...] Now,I want to use this variable 'rows' in another sql query,say,of the following kind:
query2="""insert into table xyz(select * from abc where date_time = '%s')"""%(rows)
cur.execute(query2)
This gives me an error which is as follows:
DataError:invalid input syntax for type timestamp : "[((datetime.datetime(2014,6,6,23,0),)]"
I am totally new to learning Python. Any help would be appreciated.
I tried the following and it worked:
query2 ="""insert into table xyz(select * from abc where date_time = %s)"""
cur.execute(query2,(rows))