COMMAND_TIMEOUT
Set the query execution timeout for the endpoint.
Keywords
command_timeout, timeout
Syntax
timeout <interval>
command_timeout <interval>Or using custom parameter syntax:
timeout = <interval>
command_timeout = <interval>The value uses PostgreSQL interval format:
| Format | Example |
|---|---|
| Seconds | 30s, 30 seconds, 30sec |
| Minutes | 5m, 5 minutes, 5min |
| Hours | 1h, 1 hour, 1 hours |
Default Value
The default timeout is configured via NpgsqlRest.CommandTimeout in configuration. If not set, defaults to 30 seconds.
Examples
Short Timeout
sql
create function quick_lookup(_id int)
returns json
language sql
as $$select row_to_json(t) from table t where id = _id$$;
comment on function quick_lookup(int) is
'HTTP GET
timeout 5s';Long Running Query
sql
create function generate_report(_year int)
returns json
language sql
as $$...complex aggregation...$$;
comment on function generate_report(int) is
'HTTP GET
timeout 2 minutes
authorize';Using Interval Format
sql
comment on function slow_process() is
'HTTP POST
command_timeout 1min 30s';Behavior
- Overrides the global
NpgsqlRest.CommandTimeoutconfiguration for this endpoint. - Query is cancelled if it exceeds the timeout.
- On timeout, returns the response configured in
ErrorHandlingOptions.TimeoutErrorMapping.
Timeout Response
When a command times out, the response is determined by the TimeoutErrorMapping configuration:
json
{
"ErrorHandlingOptions": {
"TimeoutErrorMapping": {
"StatusCode": 504,
"Title": "Command execution timed out",
"Details": null,
"Type": null
}
}
}Default timeout response: HTTP 504 Gateway Timeout
See Error Handling for customizing timeout responses.
Related
- NpgsqlRest Options configuration - Set global
CommandTimeoutdefault - Error Handling configuration - Configure
TimeoutErrorMappingresponse - Comment Annotations Guide - How annotations work
- Configuration Guide - How configuration works
Related Annotations
- BUFFER_ROWS - Control row buffering
- RETRY_STRATEGY - Retry on failure