JSON payload records are imported as VARCHAR. Creating a view allows you to:
- CAST the payload fields to a valid data type
- Rename the header fields using case insensitive naming. Although the example shows the headers in mixed case, you may use any mix of case you want in queries.
The examples use a sample river flow data set. To use your own data, replace the table and column names, and authorization object. See Variable Substitutions for Examples for the credentials and location values for the sample data set.
- To run NOS-related commands, log on to the database as a user with the required privileges.
- If it does not exist, create the foreign table or ask your database administrator to create the foreign table called riverflow_json_path: See Filtering on the Payload Column of a Foreign Table.
- Create a view on the foreign table:
CREATE VIEW riverflowview_json(site_no,datetime,flow,gageheight,precipitation,gageheight2) AS ( SELECT payload.site_no,payload.datetime,payload.Flow,payload.GageHeight,payload.Precipitation,payload.GageHeight2 FROM riverflow_json_path );
- Query the view:
SELECT TOP 2 * FROM riverflowview_json;
Your result will be similar to the following:
site_no 09396100 datetime 2018-07-14 00:00 flow 232 gageheight 2.16 precipitation 0.00 gageheight2 2.16 site_no 09396100 datetime 2018-07-16 00:00 flow 44.7 gageheight 1.50 precipitation 0.00 gageheight2 1.50
The output is displayed vertically for readability.