Re: BUG #9198: psql -c 'SET; ...' not working - Mailing list pgsql-bugs

From Tom Lane
Subject Re: BUG #9198: psql -c 'SET; ...' not working
Date
Msg-id 25094.1392219652@sss.pgh.pa.us
Whole thread Raw
In response to BUG #9198: psql -c 'SET; ...' not working  (christoph.berg@credativ.de)
Responses Re: BUG #9198: psql -c 'SET; ...' not working
Re: BUG #9198: psql -c 'SET; ...' not working
Re: BUG #9198: psql -c 'SET; ...' not working
List pgsql-bugs
christoph.berg@credativ.de writes:
> This seems to be a bug:

> time psql -c "SET statement_timeout = '3s'; SELECT pg_sleep(2)"
> ERROR:  canceling statement due to statement timeout
> real    0m1.065s

The reason this isn't a bug is that a -c command string is sent to the
server as a single statement (PQexec call), and what "statement timeout"
controls is the total time for the whole thing.  The SET operation can't
change the already-running timer for the current statement.  It would
affect the timeout for the next statement ... but there won't be one.

Many people have complained that it's unintuitive that -c works this way
rather than breaking up the string into multiple submissions the same way
psql would do with normal input.  We're afraid to change it for fear of
breaking applications, though.  If you want behavior more like psql's
normal operation, consider

echo "SET statement_timeout = '3s'; SELECT pg_sleep(2)" | psql

            regards, tom lane

pgsql-bugs by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd
Next
From: Peter Eisentraut
Date:
Subject: Re: BUG #9189: error reading postgresql.conf in pg_createcluster