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

查看:44
本文介绍了在 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;

此功能在亚马逊的 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天全站免登陆