By creating a view, path expressions (such as $path.$siteno) become columns in the view allowing users of the view to specify WHERE clauses on those columns without being aware that the underlying table contains complex path expressions.
The names given to the columns in a view are case insensitive. Although shown in mixed case in this example, they can be referenced in SQL queries using any mix of case desired.
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 of the foreign table called riverflow_json:
REPLACE VIEW riverflowview_json AS ( SELECT CAST($path.$siteno AS CHAR(10)) TheSite, CAST($path.$year AS CHAR(4)) TheYear, CAST($path.$month AS CHAR(2)) TheMonth, CAST(SUBSTR($path.$day, 1, 2) AS CHAR(2)) TheDay, payload.site_no site_no, payload.datetime datetime, payload.Flow Flow, payload.GageHeight GageHieght, payload.Precipitation Precipitation, payload.GageHeight2 GageHeight2 FROM riverflow_json_path);