Explanation of the stored function xfer ---------------------------------------------------- It is written in PL/pgSQL language ... which is created (enabled) by default in your new database SEE: PostgreSQL programmers guide, III: Procedural Languages Other Procedural languages known to postgres: Tcl, Perl, Python, C ------------------------------------------------------- CREATE FUNCTION fom the file xfer.plsql by using the psql monitor command: \i xfer.plsql Function Prototype: int xfer (amount, from, to) What it does: transfers an amount (by issuing 2 UPDATE statements to DB server) and returns the new balance of the current_user (you) It also puts the coins in your "pouch" if you are making a withdrawal (xfer to 'out') To run this function (in psql) type: SELECT xfer(25, 'wwang', 'out'); This will "withdraw" 25 sicles from wang's account (adding it to 'out') and reveal wang's new balance. Notes: The function uses an IF THEN END IF; conditional statement The function itself is enclosed in single quotes ' ' Single quotes within the function are doubled: ''bank'' means 'bank' comments start with -- This function is now used in my java program: BankBal.class You have EXECUTE permission for the function ERROR CHECKING: There is code to RAISE EXCEPTION if either account is not FOUND (a special variable) For example this transaction will ABORT, leaving DB unchanged: begin; select xfer (20,'bank','lin'); commit;