How to add column alias?
In the previous section of vertical filtering,
the query below returns title
,description
and release_year
columns. It is common in JSON payloads, to
return these attributes in camel notation instead of underscore. This makes the column names more readable.
DB2Rest makes this possible with use of column alias syntax as shown below.
info
Column alias can be specified with a :
followed by column alias string
column_name:column_alias_string
e.x - release-year:releaseYear
- cURL
- HTTPie
curl --request GET \
--url 'http://localhost:8080/v1/rdbms/db/film?fields=title,description,release_year:releaseYear' \
--header 'User-Agent: insomnia/8.6.1'
http GET 'http://localhost:8080/v1/rdbms/db/film?fields=title,description,release_year:releaseYear' \
Accept-Profile:sakila \
User-Agent:insomnia/8.4.5
This will retrieve the following result with the 3rd column or field name as releaseYear
.
HTTP/1.1 200
Content-Type: application/json
Transfer-Encoding: chunked
[
{
"title": "ACADEMY DINOSAUR",
"description": "A Epic Drama of a Feminist And a Mad Scientist who must Battle a Teacher in The Canadian Rockies",
"releaseYear": 2006
},
{
"title": "ACE GOLDFINGER",
"description": "A Astounding Epistle of a Database Administrator And a Explorer who must Find a Car in Ancient China",
"releaseYear": 2006
},
{
"title": "ADAPTATION HOLES",
"description": "A Astounding Reflection of a Lumberjack And a Car who must Sink a Lumberjack in A Baloon Factory",
"releaseYear": 2006
},
{
"title": "AFFAIR PREJUDICE",
"description": "A Fanciful Documentary of a Frisbee And a Lumberjack who must Chase a Monkey in A Shark Tank",
"releaseYear": 2006
}
]