Hi. I am attempting to create a function to do some selects and return some information. Pretty straight forward. No matter what I do, I always get this error. Here is my stored function and how I am calling it... create function sp_list_categories(int4) returns varchar as ' DECLARE postid ALIAS FOR $1; parentid int4; BEGIN SELECT * FROM category WHERE id = postid; parentid := SELECT parent FROM category WHERE id = postid; IF parentid ISNULL THEN RETURN ELSE SELECT sp_list_categories(parentid); RETURN name; END IF; END; ' LANGUAGE 'plpgsql'; jimmydbase=# select sp_list_categories(20); ERROR: unexpected SELECT query in exec_stmt_execsql() Any and all help would be appreciated! Branden.