Skip to main content

Query for a single row

DB2Rest can fetch a single unique record with suitable filter condition. In this case the return type is a JSON object, instead of a list of objects.

Find One - Numeric filter


curl --request GET \
--url 'http://localhost:8080/v1/rdbms/pgdb/actor/one?filter=actor_id==1' \
--header 'User-Agent: insomnia/8.6.1'


HTTP Response

{
"actor_id": 1,
"first_name": "PENELOPE",
"last_name": "GUINESS",
"last_update": "2006-02-15T10:34:33.000+00:00"
}

Find One - Varchar filter


curl --request GET \
--url 'http://localhost:8080/v1/rdbms/pgdb/actor/one?filter=last_name==WAHLBERG' \
--header 'User-Agent: insomnia/8.6.1'


HTTP Response

{
"actor_id": 2,
"first_name": "NICK",
"last_name": "WAHLBERG",
"last_update": "2006-02-15T10:34:33.000+00:00"
}

Find One - Error


curl --request GET \
--url 'http://localhost:8080/v1/rdbms/pgdb/actor/one?filter=last_name==ROSHAN' \
--header 'User-Agent: insomnia/8.6.1'


HTTP Error Response

{
"type": "https://db2rest.com/error/generic-error",
"title": "Generic Data Access Error",
"status": 400,
"detail": "Incorrect result size: expected 1, actual 3",
"instance": "/v1/rdbms/pgdb/actor/one",
"errorCategory": "Data-access-error",
"timestamp": "2024-06-09T17:43:34.802133Z"
}

The error message states that only 1 row was expected, but the database query returned 3 instead.