Here are some notes on how I got started on the PostgresSQL system for the database module of CS3.  From a DCS machine type.

     psql -u -h goldfish

and enter your userid and password at the prompt.   If you are outside the DCS network  you can connect via ssh to and then proceed as above. You will find yourself in this amazingly clunky world of command-line interaction -- a great way to find out what programming was like 25 years ago!

[You should have your userid and password . Go to the JCMB if not.  If your password doesn't work, send me mail.]

Try entering something very simple like

     create table blah (blahblah integer);
     insert into blah values(3);
     insert into blah values(4);
     select * from blah;

You rapidly discover that  this is not the way to deal with SQL and that you should be editing file
and opening it from SQL.  This is done with the \i <filename> command..  So, for example , I created the file blah.txt with the following contents

     create table likes(drinker char(10), beer char(10));

     insert into likes values('Edward', 'Bud');
     insert into likes values('Edward', 'Molson');
     insert into likes values('James', 'Belhaven');
     insert into likes values('James', 'Bud');
     insert into likes values('James', 'Molson');
     insert into likes values('Stuart', 'McEwans');

     // The people and the beers they don't like
     (select distinct l1.drinker, from likes l1, likes l2)
     (select * from likes);

Then I typed
       \i blah.txt;
Try it!

A note on the first homework problem.  Use VARCHAR(something) for the type of names.  This way you can get at the last two characters with a combination of the  SUBSTR and CHAR_LENGTH functions.   Look in the user manual, chapter 5, for information on functions.

Notes on SQL:

The implementation is also rather restrictive.  You cannot create arbitrary views!  Instead you can say
      create table foo as
      select  ...
In fact it's worse than this.  Even simple queries involving views go wrong!   Don't use them.

This gives you an alternative way of breaking up queries into subqueries, but this may not be optimal (shouldn't matter on small examples) and you have to remember to delete the tables in the likely event that you got things wrong the first time round!