问题描述
在T-SQL中是否有类似表变量的内容?
在Sql Server中,它看起来像这样:
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.
这里是描述: http://odetocode.com/Articles/365.aspx
推荐答案
为 @Clodoaldo评论:在PostgreSQL中使用临时表.例如:
As @Clodoaldo commented: use a temporary table in PostgreSQL. For your example:
CREATE TEMP TABLE product_totals (
product_id int
, revenue money
);
手册中有关 CREATE TABLE
的更多信息在这里可以找到此报价:
More information in the manual about CREATE TABLE
where you can find this quote:
未记录的表是PostgreSQL 9.1的某些相关功能.他们通过不写 WAL 来节省磁盘写操作.这是由Robert Haas讨论的功能.
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.
此外,关于money
数据类型:
这篇关于PostgreSQL表变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!