Skip to content
Written with Claude

RESPONSE_NULL_HANDLING

Also known as

response_null, text_response_null_handling (with or without @ prefix)

Control how NULL results are returned in plain text responses when the execution returns NULL from the database.

Syntax

code
@response_null <mode>
@response_null_handling <mode>
@text_response_null_handling <mode>

Values

ValueDescription
empty_stringReturns an empty string response with status code 200 OK (default)
null_literalReturns a string literal "NULL" with status code 200 OK
no_content or 204_no_contentReturns status code 204 NO CONTENT

Examples

Return Empty String for NULL

sql
sql
comment on function get_value(_id int) is
'HTTP GET
@response_null empty_string';

If result is NULL → Response body: ""

Return 204 for NULL

sql
sql
comment on function find_record(_id int) is
'HTTP GET
@response_null 204_no_content';

If result is NULL → HTTP 204 with no body

Return JSON null

sql
sql
comment on function get_optional(_key text) is
'HTTP GET
@response_null null_literal';

If result is NULL → Response body: null

Configuration Default

You can set the default behavior for all endpoints in appsettings.json:

json
json
{
  "NpgsqlRest": {
    "TextResponseNullHandling": "NoContent"
  }
}

Available values: EmptyString (default), NullLiteral, NoContent.

This sets the default for all endpoints, which can then be overridden per-endpoint using comment annotations.

Comments