Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I am working on complex query that takes hours to execute. I am using PSycopg2 to

By reading this Post . I added this statement :

 import os.environ
    ['PGOPTIONS'] = '-c statement_timeout=1000000'

Now, I am getting an error every-time, I execute this query :

import psycopg2
>>> cnn = psycopg2.connect("dbname=test options='-c statement_timeout=1000'")
>>> cur = cnn.cursor()
>>> cur.execute("select pg_sleep(200000)")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
psycopg2.extensions.QueryCanceledError: canceling statement due to statement timeout

My question: How can I force the application to take a long time to process the query ?

share|improve this question
    
What's your question? The obvious thing to do seems to be "do not set a timeout if you do not want one". – Craig Ringer Feb 13 '14 at 2:00
    
Craig Ringer: I wanted to force the application to take a long time to process the query ? – user3001937 Feb 13 '14 at 2:19

If you want your app to take a long time to process a query, you must remove the statement timeout that is forcing it to terminate early.

Remove:

 import os.environ
    ['PGOPTIONS'] = '-c statement_timeout=1000000'

and in your connection string remove the options entry.

>>> cnn = psycopg2.connect("dbname=test")

Now, if you instead wish to retain a timeout in general, but override it for just this query, then before the query, explicitly SET statement_timeout to override the default you set:

cur.execute("SET statement_timeout = 0")
cur.execute("select pg_sleep(200000)")

... and if that's the case why didn't you say so?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.