“ProgrammingError: syntax error at or near” when e

2019-03-06 06:39发布

I am running Python v 2.7 and psycopg2 v 2.5 I have a postgresql database function that returns a sql query as a text field.

I am using the following code to call the function and extract the query from the text field.

cur2.execute("SELECT * FROM historian.generate_get_archive_data_sql(%s, '*',public.get_dcs_datetime_from_timestamp(%s),public.get_dcs_datetime_from_timestamp(%s))",(row,old_time,current_time))
while True: #Indefinite Loop
    row2 = cur2.fetchone()
    query2 = str(row2)
    cur3.execute(query2)

I seem to be getting the following error when running the script,

ProgrammingError: syntax error at or near "'SELECT * FROM historian._73b4f984f30b4c68a871fac1c53a1b8f_45907294814208000 WHERE archive_datetime BETWEEN 45907381384722560 AND 45907381384732560 ORDER BY archive_datetime;'" LINE 1: ('SELECT * FROM historian.73b4f984f30b4c68a871fac1c53a1b8f...

When i run the query on the postgresql server it executes fine. Can someone help me understand what i am doing wrong ? . Thanks.

1条回答
虎瘦雄心在
2楼-- · 2019-03-06 07:33

It'd add more clarity if you could describe your table schema in the question.

The probably mistake could be that either of the following parameters that you are using for string formatting is None.

(row,old_time,current_time)

Please check your code to resolve the same.

查看更多
登录 后发表回答