COMMAND_TIMEOUT
Also known as
timeout (with or without @ prefix)
Set the query execution timeout for the endpoint.
Syntax
@timeout <interval>
@command_timeout <interval>Or using custom parameter syntax:
@timeout = <interval>
@command_timeout = <interval>The value uses the interval format. Common examples:
| Unit | Examples |
|---|---|
| Microseconds | 1000us, 1000usec, 1000microseconds |
| Milliseconds | 500ms, 500msec, 500milliseconds |
| Seconds | 30, 30s, 30sec, 30seconds |
| Minutes | 5m, 5min, 5minutes |
| Hours | 1h, 1hour, 1hours |
| Days | 1d, 1day, 1days |
| Weeks | 1w, 1week, 1weeks |
Single Token Requirement
The @timeout annotation reads only the first token after the keyword. Use formats without spaces to avoid parsing issues. Numbers without a unit default to seconds.
Default Value
The default timeout is configured via NpgsqlRest.CommandTimeout in configuration. If not set, defaults to 30 seconds.
Examples
Short Timeout
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
create function generate_report(_year int)
returns json
language sql
as $$...complex aggregation...$$;
comment on function generate_report(int) is
'HTTP GET
@timeout 2min
@authorize';Using Seconds Format
comment on function slow_process() is
'HTTP POST
@command_timeout 90s';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:
{
"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
- Interval Format - Complete interval format reference
- 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