Hi all,
Prac 04 and Prac 05 videos are out:
https://www.youtube.com/watch?v=8F-gkSwiYbE&list=PLRalM05yyRqUQu81nFdV2JY4sfqa-gkfm&index=2
https://www.youtube.com/watch?v=VDUheECb_xU&list=PLRalM05yyRqUQu81nFdV2JY4sfqa-gkfm&index=1
Hope these help you.
3311 Team
Hi everyone,
Please note that Week 4 Monday and Thursday demonstration scripts are located in:
/import/adams/A/cs3311/web/26T1/lectures/week04-monday/sql/
/import/adams/A/cs3311/web/26T1/lectures/week04-thursday/sql/
We got some interesting questions from lectures this week:
1. Why RETURN NEW in an AFTER trigger?
Even though an AFTER INSERT trigger cannot modify the row being inserted (because the operation is already complete), PostgreSQL still requires a RETURN statement.
2. Dropping overloaded functions
If you have multiple functions named seq() with different signatures (parameters), PostgreSQL treats each as a unique entity.
3. Why our user defined mycount(*) fail.
Consider the following user defined aggregate:
create or replace function mycount_trans(state integer, val anyelement)
returns integer
as $$
begin
return state + 1;
end;
$$ language plpgsql;
create aggregate mycount(anyelement) (
sfunc = mycount_trans,
stype = integer,
initcond = '0'
);
You will notice that the following code works:
SELECT bar, mycount(bar) FROM sells GROUP BY bar;
However, the following code does not work.
SELECT bar, mycount(*) FROM sells GROUP BY bar;
This is because, the * symbol is a special token that represents "all columns of the table. The built-in count(*) is a hardcoded exception in the database engine that knows how to count rows without needing a specific column. Our user defined aggregate my count did not implement this exception.
Have a good weekend! Let's have more discussions like this in class.
COMP3311 Team
The autotest for Assignment 1 has been released. You can use the following command to test your work:
3311 autotest ass1