2016-07-26 20 views

回答

1

因为一时你执行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)