Postgresql 将变量中的值存储为红移
我试图在tw变量中存储两个变量 例如:Postgresql 将变量中的值存储为红移,postgresql,amazon-redshift,Postgresql,Amazon Redshift,我试图在tw变量中存储两个变量 例如: var1=$(select max(columnA) from table) var2=$(select min(columnA) from table) 我可以合并上面的语句并执行相同的语句一次,然后将max value存储在var1中,将min value存储在var2中吗 我使用的是Redshift DB。不幸的是,AWS Redshift不支持变量或任何类型的过程特性(PL/pgSQL),如触发器、存储过程/函数等。不幸的是,AWS Redshi
var1=$(select max(columnA) from table)
var2=$(select min(columnA) from table)
我可以合并上面的语句并执行相同的语句一次,然后将max value存储在var1中,将min value存储在var2中吗
我使用的是Redshift DB。不幸的是,AWS Redshift不支持变量或任何类型的过程特性(PL/pgSQL),如触发器、存储过程/函数等。不幸的是,AWS Redshift不支持变量或任何类型的过程特性(PL/pgSQL),如触发器、存储过程/函数,等等。我知道这个问题很老,但我也需要找到问题的解决方案。在这里玩了很多之后,我想出了一个解决办法
-- Create a temp table for storing the variables
create temp table tmp_vars (
x int,
y date
);
-- Store the values in the temp table
insert into tmp_vars (x, y) values
((select max(id) from table1),
(select max(date) from table2));
-- Use the variable in a query
select *
from some_table
where date >= (select y from tmp_vars limit 1);
-- Drop the temp table
drop table tmp_vars;
我知道这个问题由来已久,但我也需要找到解决这个问题的办法。在这里玩了很多之后,我想出了一个解决办法
-- Create a temp table for storing the variables
create temp table tmp_vars (
x int,
y date
);
-- Store the values in the temp table
insert into tmp_vars (x, y) values
((select max(id) from table1),
(select max(date) from table2));
-- Use the variable in a query
select *
from some_table
where date >= (select y from tmp_vars limit 1);
-- Drop the temp table
drop table tmp_vars;
不能在红移中定义变量 但您可以执行以下操作:
WITH
part1 as (select max(columnA) myMax from table),
part2 as (select min(columnA) myMin from table)
SELECT part1.myMax, part2.myMin from part1, part2
不能在红移中定义变量 但您可以执行以下操作:
WITH
part1 as (select max(columnA) myMax from table),
part2 as (select min(columnA) myMin from table)
SELECT part1.myMax, part2.myMin from part1, part2