You could use this to get the last insert id...
CREATE TABLE test (
id serial,
something int not null
);
This creates the sequence test_id_seq. Now do the following after inserting something into table test:
INSERT INTO test (something) VALUES (123);
SELECT currval('test_id_seq') AS lastinsertid;
lastinsertid should contain your last insert id.