Re: SQL works but same function is confused - Mailing list pgsql-general

From Rob Sargent
Subject Re: SQL works but same function is confused
Date
Msg-id 533B584C.1060005@gmail.com
Whole thread Raw
In response to SQL works but same function is confused  ("Bui, Michelle P" <michelle.p.bui@boeing.com>)
List pgsql-general
CREATE OR REPLACE FUNCTION get_status

RETURNS TABLE (category SMALLINT, status TEXT, tool_count BIGINT) AS

$BODY$

 

#variable_conflict use_variable

DECLARE

change this to "s_status TEXT;" I think it's conflicting with the column alias of same

v_status TEXT;

BEGIN

    RETURN QUERY SELECT category, v_status as status, count (tool_id) AS tool_count

    FROM

    (SELECT distinct category, tool_id, ‘active’ as v_status

FROM tools

                                 WHERE time >= 123456

                                UNION

                SELECT distinct e1.category, e1.tool_id, ‘inactive’ as v_status

                FROM tools e1

                WHERE not exists

                                (SELECT e2.category, e2.tool_id

                                FROM tools e2

                                WHERE e2.sim_time >= 123456

                                AND e2.category = e1.category

                                AND e2.tool_id = e1.tool_id)

   ) AS derivedTable

GROUP BY category, Status;

 

END; $BODY$

LANGUAGE plpgsql;

 

 

Thanks in advance for your insight or suggestion!

 

Michelle

 


pgsql-general by date:

Previous
From: "Bui, Michelle P"
Date:
Subject: SQL works but same function is confused
Next
From: Rob Sargent
Date:
Subject: Re: SQL works but same function is confused