0

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Figured out what the problem was, query2 = str(row2), was enclosing the converted string in single quotes. Had to strip the single quotes from the string before passing it to execute() to get the sql query to execute correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.