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 t1, t1 from (select getdate() as t1);
:
select getdate() as t1, 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)