Just throw a:
print "<pre>";
print $SQL_string;
print "</pre>";
in your program and toss what comes out of that into psql and see what it says about it.
For a unique id, there are two kinds. There's a variable assigned to every single row by postgresql that's called the object id, and is referenced by the field name of OID. It is an 8 byte int I believe.
So, if you were to do something like:
select *,OID from table;
You'd get back all the columns for each row, plus the OID for each row.
If you do an insert command, you can use pg_getlastoid($result_id) to find out what OID it had and hit it again right away.
OIDs are unique across an entire database, not just within a table. Asking for a record using an OID from another tables rows will result in an error.
The other type of variable is an autoincrementing key, called a SERIAL type. You declare them like so:
create table test (
column1 text,
column2 text,
columnn text,
int1 int,
int2 int,
intn int,
id_no SERIAL);
A serial type autoincrements to a new number for every row you insert (i.e. you don't insert the id_no above, it is created and inserted alongside your data when you insert a table.