Hi, A typical question that is probably asked before, but I can't find an answer in the archives or in the doc. Is there a SQL function for getting the last inserted ID for a auto increment or serial field? PostgreSQL has lastval(). I know it is returned in the query result, but I need to have the value inside a SQL function. Also I know that if you manually create a sequence for ID generation you can get the next value with: SELECT NEXT VALUE FOR seq_freq INTO freqid; But we are trying to keep our queries as generic as possible (close to impossible, but still) hence we want to use the SERIAL type. Or is there a way to find out what is the name of the sequence made when giving a SERIAL type to a column? thanks, -- Gijs Molenaar http://www.astro.uva.nl/people/gijs-molenaar/