Skip site navigation (1) Skip section navigation (2)

Usage of RETURN QUERY

From: "Eugene Dorofeyev" <edorofeyev(at)gmail(dot)com>
To: <pgsql-novice(at)postgresql(dot)org>
Subject: Usage of RETURN QUERY
Date: 2010-12-08 10:39:53
Message-ID: 000901cb96c4$40559ca0$c100d5e0$@gmail.com (view raw or flat)
Thread:
Lists: pgsql-novice
Hello,

I'm trying to use RETURN QUERY in a function (see query below) in order to
return list of issues and number of times when each issue occurred.

When I try to run the query, it outputs:

ERROR:  syntax error at or near "RETURN"
LINE 5: RETURN QUERY SELECT COUNT(tbl_rpc_data.data) AS count, tbl_r...
        ^
********** Error **********

ERROR: syntax error at or near "RETURN"
SQL state: 42601

I also tried running RETURN QUERY EXECUTE '...' USING ... -- the same
result.

I'm using 'PostgreSQL 9.0.1, compiled by Visual C++ build 1500, 64-bit	' on
64-bit Windows 7 Ultimate.


The text of the query:

--DROP FUNCTION dbglogs_golden.get_grouped_issues_by_agents(integer[]);

CREATE OR REPLACE FUNCTION
dbglogs_golden.get_grouped_issues_by_agents(_p_agent_ids integer[])
  RETURNS TABLE(_count integer, _desc text) AS $$

RETURN QUERY SELECT COUNT(tbl_rpc_data.data) AS count, tbl_rpc_data.data
FROM dbglogs_golden.tbl_rpc_messages, dbglogs_debug.tbl_severity_levels,
dbglogs_golden.tbl_rpc_data, dbglogs_product_agent.tbl_product_agents
WHERE tbl_severity_levels.severity_level_id =
tbl_rpc_messages.severity_level_id AND
      tbl_rpc_data.data_id = tbl_rpc_messages.data_id AND
      tbl_product_agents.product_agent_id =
tbl_rpc_messages.product_agent_id AND
      tbl_rpc_messages.product_agent_id = ANY(_p_agent_ids) AND
      tbl_severity_levels.severity_level_id IN (1, 2, 4, 5)
GROUP BY tbl_rpc_data.data
ORDER BY count DESC;

END;

$$ LANGUAGE 'plpgsql';
ALTER FUNCTION dbglogs_golden.get_grouped_issues_by_agents(integer[]) OWNER
TO ed;




Responses

pgsql-novice by date

Next:From: Machiel RichardsDate: 2010-12-08 13:07:22
Subject: PGstatspack installation problem
Previous:From: Machiel RichardsDate: 2010-12-07 11:47:49
Subject: Re: Postgresql resource / linux resources

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group