structure of query does not match function result type
<p>After changing type (by casting) from bigint to text my PLPGSQL function stopped working. This is the error I am getting:</p>

<pre><code>dev=&gt; select * from app.get_companies(4,808739954140037) ;
NOTICE:  Data rows were NOT found (structure of query does not match function result type)
 company_id_str | company_name 
----------------+--------------
(0 rows)

dev=&gt; 
</code></pre>

<p>And this is my function:</p>

<pre><code>CREATE OR REPLACE FUNCTION app.get_companies(ident_id bigint,sess bigint)
RETURNS TABLE(company_id_str text,company_name text) as $$
DECLARE
    server_session bigint;
BEGIN
    select app.session.session from app.session where app.session.identity_id=ident_id and app.session.session=sess into server_session;
    IF FOUND
    THEN
        BEGIN
            RETURN QUERY SELECT quote_ident(app.company.company_id::text)::text as company_id_str,app.company.name as company_name FROM app.company,app.identcomp WHERE app.company.company_id=app.identcomp.company_id and app.identcomp.identity_id=ident_id;
        EXCEPTION
            WHEN OTHERS THEN
                RAISE NOTICE 'Data rows were NOT found (%)',SQLERRM;
                RETURN;

        END;
    ELSE
        RAISE NOTICE 'Session row was NOT found';
        RETURN;
    END IF;
END;
$$ LANGUAGE plpgsql;
</code></pre>

<p>Why is this error happening if I am applying the cast and I am defining the output as TABLE ?</p>

<p>The app.company table is defined as:</p>

<pre><code>create table app.company (
    company_id          bigserial,
    date_inserted       timestamp,
    name                varchar(64)
);
</code></pre>