0
select now() as t1,t1;
error :- ERROR: 42703: column "t1" does not exist如何选择查询中使用函数列
的结果应该是:
select now() as t1,t1;
7/26/2016 7/26/2016
select now() as t1,t1;
error :- ERROR: 42703: column "t1" does not exist如何选择查询中使用函数列
的结果应该是:
select now() as t1,t1;
7/26/2016 7/26/2016
因为一时你执行select
您的查询不起作用,列t1
尚未确定。此外,正如您使用Amazon Redshift标记了您的问题一样,请让我注意您将无法使用now()
,但可以使用getdate()
代替。
解决您的问题,您可以复制now()
/getdate()
逻辑:
select getdate() as t1, getdate() as t1;
或从子查询中使用一次:
select t1, t1 from (select getdate() as t1);
无论是一个会给你:
t1 | t1
------------------------------+------------------------------
2016-07-28 06:43:46.23357+00 | 2016-07-28 06:43:46.23357+00
(1 row)
如果您需要的输出看起来完全一样在你的问题:
select
t1
, t1
from (
select
regexp_replace(
to_char(CURRENT_DATE, 'MM/DD/YYYY') -- gives 07/26/2016
, '0([0-9]{1}\/)' -- stores "7/" in $1
, '$1'
) as t1
);
,并提供:
t1 | t1
-----------+-----------
7/28/2016 | 7/28/2016
(1 row)