Re: BUG #9198: psql -c 'SET; ...' not working

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: christoph(dot)berg(at)credativ(dot)de
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #9198: psql -c 'SET; ...' not working
Date: 2014-02-12 15:40:52
Message-ID: 25094.1392219652@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

christoph(dot)berg(at)credativ(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Peter Eisentraut 2014-02-12 16:02:53 Re: BUG #9189: error reading postgresql.conf in pg_createcluster
Previous Message Bruce Momjian 2014-02-12 14:31:51 Re: BUG #8354: stripped positions can generate nonzero rank in ts_rank_cd