在RedShift中声明一个变量 [英] Declare a variable in RedShift

查看:433
本文介绍了在RedShift中声明一个变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

SQL Server可以声明一个变量,然后在查询中调用该变量,如下所示:

SQL Server has the ability to declare a variable, then call that variable in a query like so:

DECLARE @StartDate date;
SET @StartDate = '2015-01-01';

SELECT *
FROM Orders
WHERE OrderDate >= @StartDate;

此功能是否可以在Amazon的RedShift中使用?从文档中,可以看到DECLARE仅用于游标. SET似乎是我要寻找的功能,但是当我尝试使用它时,出现错误.

Does this functionality work in Amazon's RedShift? From the documentation, it looks that DECLARE is used solely for cursors. SET looks to be the function I am looking for, but when I attempt to use that, I get an error.

set session StartDate = '2015-01-01';
 [Error Code: 500310, SQL State: 42704]  [Amazon](500310) Invalid operation: unrecognized configuration parameter "startdate";

是否可以在RedShift中执行此操作?

Is it possible to do this in RedShift?

推荐答案

否,Amazon Redshift没有变量的概念. Redshift本身以PostgreSQL形式出现,但经过了高度修改.

No, Amazon Redshift does not have the concept of variables. Redshift presents itself as PostgreSQL, but is highly modified.

在2014 AWS re:Invent会议上提到了用户定义函数,这可能满足您的一些需求.

There was mention of User Defined Functions at the 2014 AWS re:Invent conference, which might meet some of your needs.

2016年更新:标量

Update in 2016: Scalar User Defined Functions can perform computations but cannot act as stored variables.

这篇关于在RedShift中声明一个变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆