Is there anything like table variables in T-SQL?
In Sql Server it looks like this:
DECLARE @ProductTotals TABLE
(
ProductID int,
Revenue money
)
Then in procedure I can:
INSERT INTO @ProductTotals (ProductID, Revenue)
SELECT ProductID, SUM(UnitPrice * Quantity)
FROM [Order Details]
GROUP BY ProductID
And manipulate with this variable like an ordinary table.
Here is description: http://odetocode.com/Articles/365.aspx
As @Clodoaldo commented: use a temporary table in PostgreSQL. For your example:
More information in the manual about
CREATE TABLE
where you can find this quote:Unlogged tables are a somewhat related feature of PostgreSQL 9.1. They save disk writes by not writing to WAL. Here is a discussion of the features by Robert Haas.
Aside, concerning the
money
data type:You can you array of composite type instead