Refactoring a PL/pgSQL to output like select queries, instead of text
===

I wrote a function that outputs a PostgreSQL select query well formed in text form. Now I don't want to output a text anymore, I want my function output as a select query. In my research I found out there is two ways of doing this using closed cursors: `OPEN-FOR-EXECUTE` or `FOR-IN-EXECUTE-LOOP`. So far so good.

But I don't know what I should expect for output, because it is defined in the function's progress; How do I define this 'dynamic' type and return the result as select query does?

    CREATE OR REPLACE FUNCTION data_of(integer)
      RETURNS text AS
    $BODY$
	DECLARE
          --Declaring variables

	BEGIN
          --Doing some crazy stuff

          result := 'SELECT\r\nDatahora,' || sensors ||
          '\r\n\r\nFROM\r\n' || type ||
          '\r\n\r\nWHERE\r\nnomepcd=' || $1 ||'\r\n\r\nORDER BY Datahora;';

          RETURN result;
	END;
    $BODY$
    LANGUAGE 'plpgsql' VOLATILE;
    ALTER FUNCTION data_of(integer) OWNER TO postgres;