You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/references/api/preferences.rst
+36Lines changed: 36 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,6 +15,7 @@ The following preferences are supported.
15
15
- ``Prefer: missing``. See :ref:`prefer_missing`.
16
16
- ``Prefer: max-affected``, See :ref:`prefer_max_affected`.
17
17
- ``Prefer: tx``. See :ref:`prefer_tx`.
18
+
- ``Prefer: timeout``. See :ref:`prefer_timeout`.
18
19
19
20
.. _prefer_handling:
20
21
@@ -296,3 +297,38 @@ With :ref:`RPC <functions>`, the preference is honored completely on the basis o
296
297
.. note::
297
298
298
299
It is important for functions to return ``SETOF`` or ``TABLE`` when called with ``max-affected`` preference. A violation of this would cause a :ref:`PGRST128 <pgrst128>` error.
300
+
301
+
302
+
.. _prefer_timeout:
303
+
304
+
Timeout
305
+
=======
306
+
307
+
You can set `statement_timeout <https://www.postgresql.org/docs/current/runtime-config-client.html#GUC-STATEMENT-TIMEOUT>`_ for the request using this preference. This works in combination with ``handling=strict`` preference in the same header.
308
+
309
+
Currently, the header only accepts integer value indicating the ``seconds`` that are set as timeout value. To demonstrate, see the following example:
Copy file name to clipboardExpand all lines: test/spec/Feature/Query/PreferencesSpec.hs
+60Lines changed: 60 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -236,3 +236,63 @@ spec =
236
236
`shouldRespondWith`
237
237
[json| {"code":"PGRST128","details":null,"hint":null,"message":"Function must return SETOF or TABLE when max-affected preference is used with handling=strict"} |]
238
238
{ matchStatus =400 }
239
+
240
+
context "Prefer: timeout and handling=strict"$do
241
+
it "should fail when timeout is less than the query time"$
242
+
request methodGet "/rpc/sleep?seconds=4"
243
+
[("Prefer", "handling=strict, timeout=3")]
244
+
""
245
+
`shouldRespondWith`
246
+
[json| {"code":"57014","details":null,"hint":null,"message":"canceling statement due to statement timeout"} |]
247
+
{ matchStatus =500
248
+
, matchHeaders = [ matchContentTypeJson ]
249
+
}
250
+
251
+
it "should fail when timeout is equal to the query time"$
252
+
request methodGet "/rpc/sleep?seconds=3"
253
+
[("Prefer", "handling=strict, timeout=3")]
254
+
""
255
+
`shouldRespondWith`
256
+
[json| {"code":"57014","details":null,"hint":null,"message":"canceling statement due to statement timeout"} |]
257
+
{ matchStatus =500
258
+
, matchHeaders = [ matchContentTypeJson ]
259
+
}
260
+
261
+
it "should succeed when timeout is more than the query time"$
0 commit comments