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. See Setting Up to Run JSON Examples.
Run the JSON_KEYS function to display the names of all attributes contained within the payloads of the JSON objects being accessed by the foreign table called riverflow_json. Once these attributes have been displayed, any of them can be specified within an SQL statement SELECT clause using DOT notation to display values, or in the WHERE clause to limit which records are returned for viewing:
SELECT DISTINCT * FROM JSON_KEYS ( ON (SELECT payload FROM riverflow_json) ) AS jsonKeys;
JSONKeys ---------------- "BatteryVoltage" "Flow" "Precipitation" "Conductance" "Velocity" "datetime" "WaterVelocity" "GageHeight2" "site_no" "Temp" "GageHeight"
The results are different from the results of SELECT TOP N because not all records contain all of the attributes, so TOP N may return records with only a subset of the attributes.If you have multiple files in your location with different headers, all headers from all resulting files appear.