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;
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";
Is it possible to do this in RedShift
?
No, Amazon Redshift does not have the concept of variables. Redshift presents itself as PostgreSQL, but is highly modified.
There was mention of User Defined Functions at the 2014 AWS re:Invent conference, which might meet some of your needs.
Update in 2016: Scalar User Defined Functions can perform computations but cannot act as stored variables.