summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-01-01 13:16:53 -0700
committermo khan <mo.khan@gmail.com>2020-01-01 13:16:53 -0700
commite798c9e23de3bed79665b3081f7764aa9437e152 (patch)
tree3de1e9bc774dc8f59e932a5839b297d8c037174d
parenteee866de5730b8cd5859444fda79ceb46b24ca18 (diff)
Complete lab 2
-rw-r--r--labs/2/README.md47
1 files changed, 46 insertions, 1 deletions
diff --git a/labs/2/README.md b/labs/2/README.md
index ea87c0f..4024377 100644
--- a/labs/2/README.md
+++ b/labs/2/README.md
@@ -90,7 +90,52 @@ CREATE VIEW DEPT_SUMMARY (D, C, TOTAL_S, AVERAGE_S) AS
* [ ] Which of the following queries and updates would be allowed by this view (from g)? If a query or update is allowed, what would the corresponding query or update on the base relations look like? Give its result when applied to the database.
1. `SELECT * FROM DEPT_SUMMARY;`
+
+```sql
+# SELECT * FROM DEPT_SUMMARY;
+ department_id | employees_count | total_salary | average_salary
+---------------+-----------------+--------------+----------------
+ 10 | 2 | 55000 | 27500.00
+ 11 | 4 | 132000 | 33000.00
+(2 rows)
+```
+
2. `SELECT D, C FROM DEPT_SUMMARY WHERE TOTAL_S > 100000;`
+
+```sql
+# select department_id, employees_count from dept_summary where total_salary > 100000;
+ department_id | employees_count
+---------------+-----------------
+ 11 | 4
+(1 row)
+```
+
3. `SELECT D, AVERAGE_S FROM DEPT_SUMMARY WHERE C > (SELECT C FROM DEPT_SUMMARY WHERE D=4);`
+
+```sql
+# select department_id, average_salary from dept_summary where employees_count > (select employees_count from dept_summary where department_id = 4);
+ department_id | average_salary
+---------------+----------------
+(0 rows)
+```
4. `UPDATE DEPT_SUMMARY SET D=3 WHERE D=4;`
-6. `DELETE FROM DEPT_SUMMARY WHERE C > 4;`
+
+```sql
+# update dept_summary set department_id = 3 where department_id = 4;
+ERROR: 55000: cannot update view "dept_summary"
+DETAIL: Views containing GROUP BY are not automatically updatable.
+HINT: To enable updating the view, provide an INSTEAD OF UPDATE trigger or an unconditional ON UPDATE DO INSTEAD rule.
+LOCATION: rewriteTargetView, rewriteHandler.c:2880
+Time: 0.553 ms
+```
+
+5. `DELETE FROM DEPT_SUMMARY WHERE C > 4;`
+
+```sql
+# delete from dept_summary where employees_count > 4;
+ERROR: 55000: cannot delete from view "dept_summary"
+DETAIL: Views containing GROUP BY are not automatically updatable.
+HINT: To enable deleting from the view, provide an INSTEAD OF DELETE trigger or an unconditional ON DELETE DO INSTEAD rule.
+LOCATION: rewriteTargetView, rewriteHandler.c:2888
+Time: 0.427 ms
+```