Complete the code to select the JSON data from the column named 'data'.
SELECT [1] FROM my_table;To select a column in SQL, just use its name without quotes.
Complete the code to extract the value of the key 'name' from the JSON column 'data'.
SELECT data[1]'name' FROM my_table;
-> which returns JSON instead of text.The operator ->> extracts the JSON object field as text.
Fix the error in the query to filter rows where the JSON key 'age' is greater than 30.
SELECT * FROM my_table WHERE (data->>[1])::int > 30;
JSON keys must be in single quotes inside the operator.
Fill both blanks to create a JSON object with keys 'name' and 'age' from columns.
SELECT json_build_object([1], name, [2], age) FROM my_table;
Keys in JSON objects must be strings in quotes.
Fill all three blanks to filter rows where the JSON key 'status' equals 'active'.
SELECT * FROM my_table WHERE data[1]'status' [2] [3];
-> which returns JSON, not text.Use ->> to extract text, then compare with '=' to the string 'active'.
