I am wondering if you can declare a variable within a function using plpgsql which can be calculated within that function to be a table which you can then use in either a select or update statement. I am wanting to be able to calculate a variable (ie logfilename) as the table I want to then use in a select of update statement. CREATE FUNCTION sp_invoicecredit() RETURNS int4 as ' DECLARE logfilename text; countrec int4; BEGIN logfilename:= ''log1000''; select into countrec count(*) from logfilename; RETURN countrec; END; ' LANGUAGE 'plpgsql' The following I know does not work, but I am wondering it is possible to do this. Regards, Ivan