Hey Stefan, For surrogate keys there is no reason to calculate values manually. You should use sequences instead. Please, see http://www.postgresql.org/docs/8.3/static/sql-createsequence.html You may also use a SERIAL data type which creates a sequence for you automatically upon its creation. Please, see http://www.postgresql.org/docs/8.3/static/datatype-numeric.html#DATATYPE-SERIAL Since you execute INSERT command without specifying an "id" column, and there is no default value for it, then the default is NULL. So, you need to define a default and the best solution to define it as next value of sequence.
-- Regards, Dmitriy