Re: SQL works but same function is confused

Поиск
Список
Период
Сортировка
От Rob Sargent
Тема Re: SQL works but same function is confused
Дата
Msg-id 533B584C.1060005@gmail.com
обсуждение исходный текст
Ответ на SQL works but same function is confused  ("Bui, Michelle P" <michelle.p.bui@boeing.com>)
Список 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 по дате отправления:

Предыдущее
От: "Bui, Michelle P"
Дата:
Сообщение: SQL works but same function is confused
Следующее
От: Rob Sargent
Дата:
Сообщение: Re: SQL works but same function is confused