Or upgrade your server to 8.x and use dollar quoting. with dollar quoting all that is a thing of the past. CREATE FUNCTION sp_slide_create(int4) RETURNS int4 AS $$ DECLARE aScriptID ALIAS FOR $1; seqID int4 := nextval('genseq'); -- no magic needed with dollar qouting :-) BEGIN INSERT INTO tblslides (slideid) VALUES (seqID); RETURN seqID; END; $$ LANGUAGE 'plpgsql' VOLATILE ---------------------------(end of broadcast)--------------------------- TIP 9: In versions below 8.0, the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match