You have to escape the ' inside of your function definition: CREATE FUNCTION testid() RETURNS INTEGER AS 'SELECT nextval(\'seq1\');' LANGUAGE 'SQL'; The quotationmark in front of seq1 terminated the literal string that should contain your SQL statement and the parser was confused to find an 's' behind the literal string. Arne. ---------------------------(end of broadcast)--------------------------- TIP 5: Have you checked our extensive FAQ? http://www.postgresql.org/users-lounge/docs/faq.html