Reputation: 21
I have two separate PostgreSQL count queries that I would like to output as one combined report. I have done a little bit of research into this and found that it could be done through a stored procedure, but I am not sure how I should go about doing this (I'm fairly new to Postgres programming).
Both of the queries are returning counts.
Any insight into this would be much appreciated!
Upvotes: 2
Views: 1450
Reputation: 648
I don't believe PostgreSQL has stored procedures, only functions. However, you could do what you're talking about with a FUNCTION.
CREATE FUNCTION getQtyOrders(customerID int) RETURNS int AS $$
DECLARE
qty int;
BEGIN
SELECT COUNT(*) INTO qty
FROM Orders
WHERE accnum = customerID;
RETURN qty;
END;
Upvotes: 0
Reputation: 22803
You don't even need a stored procedure for this. You can just make one big query:
SELECT a.a_count, b.b_count FROM
(SELECT COUNT(*) a_count FROM table_a) AS a,
(SELECT COUNT(*) b_count FROM table_b) AS b;
Upvotes: 5