reset password
Author Message
aligh1979
Posts: 121
Posted 01:48 Oct 22, 2010 |

I am  going over the two 20 percent students functions , with cursor or query , when it says :   if random() <= 0.2 then .......  . what if it is not going to be <= 0.2 since its random , as I understand the statement above is a loop or cursor that goes over all records on the table and each time if  random() <= 0.2 then it returns the record , so for me it can not guarantee 20 percent .

aligh1979
Posts: 121
Posted 03:08 Oct 22, 2010 |

I also see that the "student_samples" function just has "return;" but the  "student_samples2"  does not return at the end ? is it like optional or there is a difference between the cursor function and the loop one?

aligh1979
Posts: 121
Posted 03:28 Oct 22, 2010 |

one more question regarding trigger functions. in the powerpoint  slide it says:

"

1.Statement triggers and after-row triggers should return NULL
and
2.For row-level insert and update triggers, the returned row becomes the row that will be inserted or will replace the row being updated
 

"

the 1st line seems correct since in the trigger example it returns null , for the 2nd line in the actual example it just returns null as 1st line says it is not returning any row? it is just inserting and have an "if" statement

what does it mean exactly?

cysun
Posts: 2935
Posted 08:04 Oct 22, 2010 |

1. Random sampling is actually a fairly complex topic. Since it's a in-class example, we don't have time to use more sophisticated sampling methods. The method we used is very simple to implement, and if the number of students is large enough, the result should be reasonably close to 20%. If you want exactly 20%, you can randomly pick one student, then randomly pick another from the remaining students, and continue until you reach 20%.

2. I forgot to write  the return statement at the end of student_samples2(), but it turns out that the function runs fine on PostgreSQL 8.4, so the return statement is indeed optional.

3. Line 2 should say "For before row-level insert and update triggers ..." as statement triggers and after row-level triggers are covered by line 1.