postgresの結果をいくつかの凝ったランキング関数で並べ替えたいのですが、簡単にするために、2つのカスタム行を追加して並べ替えたいとしましょう。
SELECT my_table.*,
extract(epoch from (age(current_date, '2012-09-12 10:43:40'::date)))/3600 AS age_in_hours
Fancy_function_counting_distance() AS distance
FROM my_table
ORDER BY distance + age_in_hours;
ただし、エラーが発生するため、機能しませんERROR: column "distance" does not exist
。カスタムの名前付き行で結果を並べ替えることはできますか?
postgres9.1.xを実行しています