PostgreSQL - use previously computed value from same query <p>I have the following sql query:</p> <pre><code>SELECT (SELECT ...) AS X, (SELECT ...) AS Y from my_table </code></pre> <p>'X' is quite hard to compute, and it's used as an input for computing Y. However, if I try to reference X within the query that computes Y or even within the main query I get the following error message:</p> <pre><code>Error: column "X" does not exist </code></pre> <p>Is there any way to reference X once it is computed? I really don't want to compute it twice, as this seems very inefficient.</p>